2

I have onclick function

if ($this->board['enablecaptcha'] == 1) { $madness='<div id="lok" onclick="capture_ld()"><a onclick="capture_ld();">Введите капчу</a> </div>';

I need something like

if ($this->board['enablecaptcha'] == 1) { $madness='<div id="lok" onload="capture_ld()"><a onload="capture_ld();">Введите капчу</a> </div>';

But <a onload="" doesn't work. Help please

5
  • Can you describe what behavior you want for the div "lok"? Commented Mar 16, 2013 at 0:45
  • @MeowMix This div should load the captcha when page is loaded Commented Mar 16, 2013 at 0:47
  • Then you should follow PSR's advice. That should work for you. Commented Mar 16, 2013 at 0:51
  • Well, i can't use <body> tag because page will break. Any alternatives how i can load "capture_ld();" without onload function? Commented Mar 16, 2013 at 0:56
  • Well, you need an event handler for "onload" so you can do stuff, in this case "capture_id()". You should be able to add it to the JS file that "capture_id()" is residing in. Like @Francois' answer. Commented Mar 16, 2013 at 1:00

2 Answers 2

2

you can use onload for body tag

<body onload="capture_ld();">
</body>

or use

 <script>
capture_ld();
</script>
Sign up to request clarification or add additional context in comments.

1 Comment

Actually, <img> tags and <iframe> tags have an onload event. You certainly cannot use it with an <a> tag like the OP was trying.
0

This div should load the captcha when page is loaded

You could use window.onload

window.onload = function(){
    capture_ld();
};

The load event fires at the end of the document loading process. At this point, all of the objects in the document are in the DOM, and all the images and sub-frames have finished loading.

2 Comments

Wahl Yeah, thanks! Now it's look like ` if ($this->board['enablecaptcha'] == 1) { $madness='<div id="lok" onload="capture_ld()"> <script> window.onload = function(){ capture_ld(); }; </script> </div>';`
@user2175917: You can remove the in-line onload="..." from the other elements as well then. Did this work for you now?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.