Jump to content

stop from submitting


hackalive

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/203841-stop-from-submitting/
Share on other sites

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

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>

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

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>

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;
}
}

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>

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;
}
}

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.