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

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.