Reputation: 1067
i want to use focus function in jquery to return to same area of the input after clicking the submit button to change code of captcha,but it didn't return to area of the input,and return to the top of the page,i looked for the same problem here,and tried all but also didn't work is there anyway to do that correctly,or another method to return to same area of input after clicking by jquery,not DOM?
<form action="" method="post">
<h4>enter pic code</h4>
<img src="captcha.php" id="captcha" />
<br />
<label><a href="#" onclick="document.getElementById('captcha').src='captcha.php?'+Math.random();"
id="change-image">change captcha code</a></label>
<input type="text" name="captcha" id="captcha-form" />
</form>
<script>
$(document).ready(function(){
$("#change-image").focus();
});
</script>
Upvotes: 1
Views: 323
Reputation: 2357
Try: onclick="document.getElementById('captcha').src='captcha.php?'+Math.random(); return false;"
adding return false;
is very important when working with event bindings to prevent default behaviour.
Upvotes: 1