hackalive Posted June 4, 2010 Share Posted June 4, 2010 So I have this form <div id='search'> <form> <input name="txtSearch" type="text" id="txtSearch" value="enter search terms here" onfocus="remSearch(this, 'enter search terms here');" onblur="chkSearch(this, 'enter search terms here');"> <button name="btnSearch" type="submit" id="btnSearch" onfoucs="return false;" onblur="return false;" onclick="return false; btnSearch();"></button> </form> </div> but btnSearch() is not executing and if I swap the return false with the btnSearch it submits, any ideas, this is really annoying me Thanks in advance Quote Link to comment Share on other sites More sharing options...
phpchamps Posted June 4, 2010 Share Posted June 4, 2010 give the code for remSearch, chkSearch and btnSearch function Quote Link to comment Share on other sites More sharing options...
hackalive Posted June 4, 2010 Author Share Posted June 4, 2010 function remSearch(a, b){ if(a.value==b){ a.value=''; }else if(a.value==''){ a.value=b; }else{ a.value=a.value; } } function chkSearch(a, b){ if(a.value=='' || a.value=='enter search terms here'){ a.value=b; $('#txtSearch').fadeOut('slow'); }else{ a.value=a.value; } } function btnSearch(){ if(a.value!='' || a.value!='enter search terms here'){ //Submit if not blank or no enter search terms here search.submit(); }else{ $('#txtSearch').fadeIn('slow'); var t=setTimeout("chkSearch('txtSearch', 'enter search terms here')",5000); } } it also uses JQuery so if you are oing to test it you will need JQuery Quote Link to comment Share on other sites More sharing options...
hackalive Posted June 4, 2010 Author Share Posted June 4, 2010 no matter the value of txtSearch is submits if I use <button name="btnSearch" type="submit" id="btnSearch" onfoucs="return false;" onblur="return false;" onclick=" btnSearch(); return false;"></button> OR not at all for <button name="btnSearch" type="submit" id="btnSearch" onfoucs="return false;" onblur="return false;" onclick="return false; btnSearch();"></button> Quote Link to comment Share on other sites More sharing options...
ignace Posted June 4, 2010 Share Posted June 4, 2010 You need to return either false or true from btnSearch(), false if you want to halt the submit of the form and true if want it to proceed. In btnSearch you would disable the button prior to returning the true statement. Quote Link to comment Share on other sites More sharing options...
hackalive Posted June 4, 2010 Author Share Posted June 4, 2010 so function btnSearch(){ return false; if(a.value!='' || a.value!='enter search terms here'){ //Submit if not blank or no enter search terms here search.submit(); }else{ $('#txtSearch').fadeIn('slow'); var t=setTimeout("chkSearch('txtSearch', 'enter search terms here')",5000); } } yeah ignace? because that doesnt work Quote Link to comment Share on other sites More sharing options...
phpchamps Posted June 4, 2010 Share Posted June 4, 2010 this is because btnSearch is also the id of your submit button.. change the either function name of the id of submit button Quote Link to comment Share on other sites More sharing options...
hackalive Posted June 4, 2010 Author Share Posted June 4, 2010 here is all my code so maybe one of you can download it and try it out to see what I mean clearlogin.js function remUsername(a, b){ if(a.value==b){ a.value=''; }else if(a.value==''){ a.value=b; }else{ a.value=a.value; } } function chkUsername(a, b){ if(a.value==''){ a.value=b; }else{ a.value=a.value; } } function remPassword(a, b){ if(a.value==b){ a.value=''; a.type='password'; }else if(a.value==''){ a.value=b; a.type='text'; }else{ a.value=a.value; } } function chkPassword(a, b){ if(a.value==''){ a.value=b; a.type='text'; }else{ a.value=a.value; a.type='password'; } } function remSearch(a, b){ if(a.value==b){ a.value=''; }else if(a.value==''){ a.value=b; }else{ a.value=a.value; } } function chkSearch(a, b){ if(a.value=='' || a.value=='enter search terms here'){ a.value=b; $('#txtSearch').fadeOut('slow'); }else{ a.value=a.value; } } function btnSearch1(){ return false; if(a.value!='' || a.value!='enter search terms here'){ //Submit if not blank or no enter search terms here search.submit(); }else{ $('#txtSearch').fadeIn('slow'); var t=setTimeout("chkSearch('txtSearch', 'enter search terms here')",5000); } } index.html <html> <head> <script type='text/javascript' src='http://10.0.0.1/lib/js/clearlogin.js'></script><script type='text/javascript' src='http://code.jquery.com/jquery-latest.js'></script> </head> <body> <div id='search'> <form> <input name="txtSearch" type="text" id="txtSearch" value="enter search terms here" onfocus="remSearch(this, 'enter search terms here');" onblur="chkSearch(this, 'enter search terms here');"> <button name="btnSearch" type="submit" id="btnSearch" onfoucs="return false;" onblur="return false;" onclick="btnSearch1();"></button> </form> </div> </body> </html> Quote Link to comment Share on other sites More sharing options...
ignace Posted June 4, 2010 Share Posted June 4, 2010 so function btnSearch(){ return false; if(a.value!='' || a.value!='enter search terms here'){ //Submit if not blank or no enter search terms here search.submit(); }else{ $('#txtSearch').fadeIn('slow'); var t=setTimeout("chkSearch('txtSearch', 'enter search terms here')",5000); } } yeah ignace? because that doesnt work If you bothered to learn JS you wouldn't have to come here asking questions to make a fool of yourself. It's function btnSearch(){ if(a.value!='' || a.value!='enter search terms here'){ //Submit if not blank or no enter search terms here search.submit(); return true; }else{ $('#txtSearch').fadeIn('slow'); var t=setTimeout("chkSearch('txtSearch', 'enter search terms here')",5000); return false; } } Quote Link to comment Share on other sites More sharing options...
phpchamps Posted June 4, 2010 Share Posted June 4, 2010 try this <script language="JavaScript1.2" type="text/javascript"> function remUsername(a, b){ if(a.value==b){ a.value=''; }else if(a.value==''){ a.value=b; }else{ a.value=a.value; } } function chkUsername(a, b){ if(a.value==''){ a.value=b; }else{ a.value=a.value; } } function remPassword(a, b){ if(a.value==b){ a.value=''; a.type='password'; }else if(a.value==''){ a.value=b; a.type='text'; }else{ a.value=a.value; } } function chkPassword(a, b){ if(a.value==''){ a.value=b; a.type='text'; }else{ a.value=a.value; a.type='password'; } } function remSearch(a, b){ if(a.value==b){ a.value=''; }else if(a.value==''){ a.value=b; }else{ a.value=a.value; } } function chkSearch(a, b){ if(a.value=='' || a.value=='enter search terms here'){ a.value=b; $('#txtSearch').fadeOut('slow'); }else{ a.value=a.value; } } function btnSearch1(){ var a = document.getElementById("txtSearch"); if(a.value!='' && a.value!='enter search terms here'){ alert("Submit Now"); //Submit if not blank or no enter search terms here document.frm_search.submit(); }else{ alert("Dont submit"); $('#txtSearch').fadeIn('slow'); var t=setTimeout("chkSearch('txtSearch', 'enter search terms here')",5000); return false; } } </script> <html> <head> <script type='text/javascript' src='http://10.0.0.1/lib/js/clearlogin.js'></script><script type='text/javascript' src='http://code.jquery.com/jquery-latest.js'></script> </head> <body> <div id='search'> <form onSubmit="return btnSearch1();" name="frm_search"> <input name="txtSearch" type="text" id="txtSearch" value="enter search terms here" onfocus="remSearch(this, 'enter search terms here');" onblur="chkSearch(this, 'enter search terms here');"> <input type="submit" name="btnSearch" id="btnSearch" onFocus="return false;" onBlur="return false;"> </form> </div> </body> </html> Quote Link to comment Share on other sites More sharing options...
hackalive Posted June 4, 2010 Author Share Posted June 4, 2010 For all your insults, your solution DOES NOT WORK, so dont tell me about learning JS so function btnSearch(){ return false; if(a.value!='' || a.value!='enter search terms here'){ //Submit if not blank or no enter search terms here search.submit(); }else{ $('#txtSearch').fadeIn('slow'); var t=setTimeout("chkSearch('txtSearch', 'enter search terms here')",5000); } } yeah ignace? because that doesnt work If you bothered to learn JS you wouldn't have to come here asking questions to make a fool of yourself. It's function btnSearch(){ if(a.value!='' || a.value!='enter search terms here'){ //Submit if not blank or no enter search terms here search.submit(); return true; }else{ $('#txtSearch').fadeIn('slow'); var t=setTimeout("chkSearch('txtSearch', 'enter search terms here')",5000); return false; } } Quote Link to comment Share on other sites More sharing options...
hackalive Posted June 4, 2010 Author Share Posted June 4, 2010 okay so may thanks to phpchamps but my problem now is that var t=setTimeout("chkSearch('txtSearch', 'enter search terms here')",5000); is not working any ideas phpchamps, and thanks for the help already given, much appreciated Quote Link to comment Share on other sites More sharing options...
ignace Posted June 4, 2010 Share Posted June 4, 2010 your solution DOES NOT WORK Sure it does, you just applied it wrong as it's: onclick="return btnSearch();" For all your insults You started big-mouthing me yeah ignace? because that doesnt work If I misinterpreted it, then I excuse myself. Quote Link to comment Share on other sites More sharing options...
hackalive Posted June 5, 2010 Author Share Posted June 5, 2010 yes you did misenterpret the yeah? party I was going for a id this what you meant I should do or have I got it wrong, sorry 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.