March 10, 201214 yr hi, I have a submit button in a web form. I want to write some javascript such that: after I submit the form, an alert window pop out, after I click ok, it focus on an input text field. the problem is, after the submit button, the page refrsh and it won't focus on it any more. could you please tell me how to solve this problem? <html> <head> <script type="text/javascript"> function getfocus() { alert("hello") document.getElementById('myAnchor').focus(); } function losefocus() { document.getElementById('myAnchor').blur(); } </script> </head> <body> <a id="myAnchor2" href="http://www.w3schools.com">Visit W3Schools.com</a> <input type="text" id="myAnchor" /> <br /><br/> <form> <input type="submit" onclick="getfocus()" value="Get focus"> <input type="button" onclick="losefocus()" value="Lose focus"> </form> </body> </html>
March 14, 201214 yr It looks like you might have to have your getfocus() function return false. This should tell the browser to not submit the form. You'll have to submit the form via javascript when you want it to submit though.
Create an account or sign in to comment