s4surbhi2218 Posted December 11, 2012 Share Posted December 11, 2012 Hey, My problem is that focus to filed happens and un focuses soon after that , however i want it to persist till user resubmits , i am using the following <html> <head> <script language="javascript"> function fnc_Validate() { var str= ''; if(document.getElementById('name1')) { if(document.getElementById('name1').value == '') { alert('Cannot be left Blank'); document.getElementById('name1').focus(); return false; } } str = "Short1.php"; document.frmname.action = str; document.frmname.submit(); } </script> </head> <body> <form name='frmname' method='post'> <input type="text" name="name1" id="name1"> <input type="text" name="name2" id="name2"> <input type="text" name="name3" id="name3"> <input type="submit" value="shorten" onclick="fnc_Validate();"> </form> </body> </html> Any help would be great , thanks Quote Link to comment Share on other sites More sharing options...
codefossa Posted December 11, 2012 Share Posted December 11, 2012 Please use code tags when you show any code. It makes it much easier to look through. Without changing a whole lot of your code .. Demo: http://xaotique.no-ip.org/tmp/28/ <html> <head> <script language="javascript"> window.addEventListener("load", function() { window.document.frmname.addEventListener("submit", function(e) { e.preventDefault(); var str= ''; if (document.getElementById('name1')) { if (document.getElementById('name1').value == '') { alert('Cannot be left Blank'); document.getElementById('name1').focus(); return false; } } str = "Short1.php"; document.frmname.action = str; document.frmname.submit(); }, false); }, false); </script> </head> <body> <form name='frmname' method='post'> <input type="text" name="name1" id="name1"> <input type="text" name="name2" id="name2"> <input type="text" name="name3" id="name3"> <input type="submit" value="shorten"> </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
s4surbhi2218 Posted December 11, 2012 Author Share Posted December 11, 2012 Please use code tags when you show any code. It makes it much easier to look through. Without changing a whole lot of your code .. Demo: http://xaotique.no-ip.org/tmp/28/ <html> <head> <script language="javascript"> window.addEventListener("load", function() { window.document.frmname.addEventListener("submit", function(e) { e.preventDefault(); var str= ''; if (document.getElementById('name1')) { if (document.getElementById('name1').value == '') { alert('Cannot be left Blank'); document.getElementById('name1').focus(); return false; } } str = "Short1.php"; document.frmname.action = str; document.frmname.submit(); }, false); }, false); </script> </head> <body> <form name='frmname' method='post'> <input type="text" name="name1" id="name1"> <input type="text" name="name2" id="name2"> <input type="text" name="name3" id="name3"> <input type="submit" value="shorten"> </form> </body> </html> this solved my prob , yes i get your point of using code tags. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.