Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disable an onChange

Status
Not open for further replies.

Quasibobo

Programmer
Oct 11, 2001
168
NL
Hi,

I have some formfields with an onChange="checkNeg()"
The form itself has an onSubmit="return(Verify())"

This function looks like this:
Code:
function Verify(){
if (!checkNeg() || !checkValues())
    {
     return(false);
    }
return (true);
}
But what happens when I hit 'ENTER' in a formfield:
the onChange="checkNeg()" runs AND the onSubmit="return(Verify())" runs.... so the alertmassages from the checkNeg() function appears twice.

Is there a way to disable onChange when submitting the form (by hitting the ENTER-button)?

Don't eat yellow snow!
 
why are u calling the function in onsubmit again???

Known is handfull, Unknown is worldfull
 
Just making sure no negative values are submitted...

Everyime a formfield gets a value, the onChange activates the checkNeg()-function. But after the alert-message ('Don't use negative values!'), the user can ignore this message and skip to the next field using his mousepointer.

So I need to check the whole form for negative values when the form is submitted.

Tu comprends?

Don't eat yellow snow!
 
but wont onchange already validate all fields? try removing the validation from ur form submit. It should still have the same functionality...

Known is handfull, Unknown is worldfull
 
yes... it validates the field, but the user can decide to ignore the alertmessage. He can easily click in the next textfield without changing the negative value.

So I need to run this checkNeg() again when submitting...

Don't eat yellow snow!
 
easy way:
validate only during submit

tough way:
can i have a sample HTML output???

Known is handfull, Unknown is worldfull
 
Easy way:
Ok.... I'll disable the ENTER-key (or ENTER = next formfield (like TAB)).

Tough way:
Here's the code (the function have other names than I mentioned in de posts!!)

Code:
<html>
<head>
<title>Bestellen per lijst</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="includes/stylesheet.css" type="text/css">
<script type="text/javascript">
<!--
function selectElement(k) {
		var obj = document.forms['invoeren'].elements['besteld_' + k];
		obj.select();
	}

function LeegVeldControle(){
for(j=0;j<document.forms['invoeren'].elements.length;j++)
	{
	if (document.forms['invoeren'].elements[j].type != 'hidden')
		{
		if(document.forms['invoeren'].elements[j].value.length==0)
			{
			alert('Vul hier wat in!\n(Dit kan bijvoorbeeld ook 0 zijn)');
			document.forms['invoeren'].elements[j].select();
			return(false);
			}
		}
	}
//return confirm('Alles klopt?');
return (true);
}

function checkNegatief(i){
a = parseFloat(document.forms['invoeren' ].elements['besteld_' + i].value);
if (a<0)
	{
	alert('Vul geen negatieve getallen in!');
	setTimeout('selectElement('+i+');', 1);
	}
}

function checkSubmitNegatief(){

for(j=0;j<document.forms['invoeren'].elements.length;j++)
	{
	if (document.forms['invoeren'].elements[j].type != 'hidden')
		{
		a = parseFloat(document.forms['invoeren' ].elements[j].value);
		if (a<0)
			{
			alert('Vul geen negatieve getallen in!');
			document.forms['invoeren'].elements[j].select();
			return(false);
			}
		}
	}
return (true);
}

function Controle(){

if (!LeegVeldControle() || !checkSubmitNegatief())
	{
	return false;
	}
return true;
}
//-->
</script>
</head>
<body onLoad="document.forms[0].elements[0].select();">
<table border="0" cellspacing="1" align="center">
<form name="invoeren" action="bestellen_per_lijst.php" method="post" onSubmit="return Controle()">
<tr>
 <td align="center" colspan="7"><font size="5"><b>Bestellen per lijst</b></font></td>
</tr>
<tr>
 <td colspan="7" align="right"><font size="4"><b>c1</b></font></td>
</tr>
<tr class="tabelhoofd">
 <td>&nbsp;Boekcode&nbsp;</td>
 <td>&nbsp;ISBN&nbsp;</td>
 <td>&nbsp;Voorraad&nbsp;</td>
 <td>&nbsp;Besteld&nbsp;</td>
 <td>&nbsp;Bestellen&nbsp;</td>
 <td>&nbsp;Titel</td>
 <td align="right">&nbsp;Auteur</td>
</tr>
 <tr class="table_row_color_1a">
  <td align="center">c1-1</td>
  <td width="80" align="center">9013007651</td>  <td align="center">0</td><td align="center">0</td>  <td align="center"><input type="text" name="besteld_1" value="0" size="3" style="text-align:center" onChange="checkNegatief(1)"><input type="hidden" name="ISBN_1" value="9013007651"></td>
   <td width="*">&nbsp;Communicatiekaart van Nederland&nbsp;</td><td align="right">&nbsp;Bakker&nbsp;</td>
 </tr>
 <tr class="">
  <td align="center">c1-2</td>
  <td width="80" align="center">9001517641</td>  <td align="center">0</td><td align="center">0</td>  <td align="center"><input type="text" name="besteld_2" value="0" size="3" style="text-align:center" onChange="checkNegatief(2)"><input type="hidden" name="ISBN_2" value="9001517641"></td>
   <td width="*">&nbsp;Basisboek Journalistiek&nbsp;</td><td align="right">&nbsp;Kussendrager&nbsp;</td>
 </tr>
 <tr class="table_row_color_1a">
  <td align="center">c1-3</td>
  <td width="80" align="center">904170499X</td>  <td align="center">0</td><td align="center">0</td>  <td align="center"><input type="text" name="besteld_3" value="0" size="3" style="text-align:center" onChange="checkNegatief(3)"><input type="hidden" name="ISBN_3" value="904170499X"></td>
   <td width="*">&nbsp;Trouw schrijfboek&nbsp;</td><td align="right">&nbsp;Berg&nbsp;</td>
 </tr>
 <tr class="">
  <td align="center">c1-4</td>
  <td width="80" align="center">9001400167</td>  <td align="center">0</td><td align="center">0</td>  <td align="center"><input type="text" name="besteld_4" value="0" size="3" style="text-align:center" onChange="checkNegatief(4)"><input type="hidden" name="ISBN_4" value="9001400167"></td>
   <td width="*">&nbsp;Samenvatten&nbsp;</td><td align="right">&nbsp;Hogen&nbsp;</td>
 </tr>
 <tr class="table_row_color_1a">
  <td align="center">c1-5</td>
  <td width="80" align="center">9001163874</td>  <td align="center">0</td><td align="center">0</td>  <td align="center"><input type="text" name="besteld_5" value="0" size="3" style="text-align:center" onChange="checkNegatief(5)"><input type="hidden" name="ISBN_5" value="9001163874"></td>
   <td width="*">&nbsp;Taaltopics: Formuleren&nbsp;</td><td align="right">&nbsp;Braas&nbsp;</td>
 </tr>
 <tr class="">
  <td align="center">c1-6</td>
  <td width="80" align="center">9001163890</td>  <td align="center">0</td><td align="center">0</td>  <td align="center"><input type="text" name="besteld_6" value="0" size="3" style="text-align:center" onChange="checkNegatief(6)"><input type="hidden" name="ISBN_6" value="9001163890"></td>
   <td width="*">&nbsp;Taaltopics: Spelling&nbsp;</td><td align="right">&nbsp;Braas&nbsp;</td>
 </tr>
 <tr class="table_row_color_1a">
  <td align="center">c1-7</td>
  <td width="80" align="center">905333775X</td>  <td align="center">0</td><td align="center">0</td>  <td align="center"><input type="text" name="besteld_7" value="0" size="3" style="text-align:center" onChange="checkNegatief(7)"><input type="hidden" name="ISBN_7" value="905333775X"></td>
   <td width="*">&nbsp;Religie in een Notendop&nbsp;</td><td align="right">&nbsp;Hondebrink&nbsp;</td>
 </tr>
 <tr class="">
  <td align="center">c1-8</td>
  <td width="80" align="center">9001181279</td>  <td align="center">0</td><td align="center">0</td>  <td align="center"><input type="text" name="besteld_8" value="0" size="3" style="text-align:center" onChange="checkNegatief(8)"><input type="hidden" name="ISBN_8" value="9001181279"></td>
   <td width="*">&nbsp;De economie in Nederland&nbsp;</td><td align="right">&nbsp;Buunk&nbsp;</td>
 </tr>
 <tr class="table_row_color_1a">
  <td align="center">c1-9</td>
  <td width="80" align="center">9001902006</td>  <td align="center">0</td><td align="center">0</td>  <td align="center"><input type="text" name="besteld_9" value="0" size="3" style="text-align:center" onChange="checkNegatief(9)"><input type="hidden" name="ISBN_9" value="9001902006"></td>
   <td width="*">&nbsp;Wisselwerk&nbsp;</td><td align="right">&nbsp;Mezach&nbsp;</td>
 </tr>
 <tr class="">
  <td align="center">c1-10</td>
  <td width="80" align="center">9059401158</td>  <td align="center">0</td><td align="center">0</td>  <td align="center"><input type="text" name="besteld_10" value="0" size="3" style="text-align:center" onChange="checkNegatief(10)"><input type="hidden" name="ISBN_10" value="9059401158"></td>
   <td width="*">&nbsp;Handboek Internetresearch&nbsp;</td><td align="right">&nbsp;Dasselaar&nbsp;</td>
 </tr>
 <tr class="table_row_color_1a">
  <td align="center">c1-11</td>
  <td width="80" align="center">9051896328</td>  <td align="center">0</td><td align="center">0</td>  <td align="center"><input type="text" name="besteld_11" value="0" size="3" style="text-align:center" onChange="checkNegatief(11)"><input type="hidden" name="ISBN_11" value="9051896328"></td>
   <td width="*">&nbsp;Beleidsterreinen van de lagere overheid&nbsp;</td><td align="right">&nbsp;Pollemans&nbsp;</td>
 </tr>
 <tr class="">
  <td align="center">c1-12</td>
  <td width="80" align="center">906283373X</td>  <td align="center">0</td><td align="center">0</td>  <td align="center"><input type="text" name="besteld_12" value="0" size="3" style="text-align:center" onChange="checkNegatief(12)"><input type="hidden" name="ISBN_12" value="906283373X"></td>
   <td width="*">&nbsp;Bestuurlijke kaart van Nederland&nbsp;</td><td align="right">&nbsp;Neelen&nbsp;</td>
 </tr>
 
<tr>
 <td colspan="7"><input type="hidden" name="verder" value="bestellen"><input type="hidden" name="lijst" value="c1">&nbsp;</td>
</tr>
<tr>
 <td colspan="7" align="center"><input type="submit" name="submit" value="Bestellen" style="width:90px">&nbsp;&nbsp;&nbsp;<input type="reset" value="Wissen" style="width:90px"></td>
 </tr>
<tr>
 <td colspan="7"><a href="javascript:history.back()">Terug</a></td>
 </tr>
</table>
</body>
</html>

Don't eat yellow snow!
 
er,
can u give me with the onchange event? its all greek and latin to me...

Known is handfull, Unknown is worldfull
 
I changed the script with the ENTER disabled.
It's fine now... thanks anyway!

BTW.... it's not greek or latin, it's dutch ;)

Don't eat yellow snow!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top