michaellunsford Posted January 15, 2007 Share Posted January 15, 2007 When I submit an empty search field, I get the error popup, but the stupid thing submits anyway. Could alert() be returning true when I click okay?[code]<form action="search.html" method="post" id="quick_search" onsubmit="submit_check();";><input name="quick_search" type="text" class="textfield" onfocus="smarter_field()" onblur="smarter_field()" size="16" /><input type="image" id="quick_search_06" src="/images/quick_search_06.jpg" onmouseover="this.src='/images/quick_search_a_06.jpg'" onmouseout="this.src='/images/quick_search_06.jpg'" /></form>[/code][code]function submit_check() { mml=document.forms['quick_search'].elements['quick_search']; if(mml.value=='') { alert('Please enter a value'); return false; } else return true;}[/code] Quote Link to comment Share on other sites More sharing options...
fenway Posted January 15, 2007 Share Posted January 15, 2007 Very strange... you can't be getting into both control paths. Quote Link to comment Share on other sites More sharing options...
michaellunsford Posted January 15, 2007 Author Share Posted January 15, 2007 After removing that loose semi-colon from the <form> tag, the page validates as xhtml 1.1. To add to the confusion, neither Safari nor FireFox is reporting any javascript error. Quote Link to comment Share on other sites More sharing options...
nogray Posted January 15, 2007 Share Posted January 15, 2007 change the submit event in the form tag to[code]onsubmit="return submit_check();">[/code]this will return the function result to the submit event. Quote Link to comment Share on other sites More sharing options...
michaellunsford Posted January 15, 2007 Author Share Posted January 15, 2007 yep. I knew it was something stupid.Thanks! Quote Link to comment Share on other sites More sharing options...
fenway Posted January 16, 2007 Share Posted January 16, 2007 Silly... should've caught that one. 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.