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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JS error when "submit" clicked

Status
Not open for further replies.

gcrighton

Technical User
Feb 23, 2002
9
ES
Hi,

I'm getting an error displayed in the task bar when I click submit in a form (only when submit is clicked). The form processes and redirects as normal, and at such a speed that I'm unable to read the error type that flashes up.

Code I'm using is included below. Can anyone shed any light?

Thanks in advance,

Gary Crighton

// Declaring form
<form name=&quot;application&quot; action=&quot;/production/socio/suscribase2.php?lang=<?PHP echo $lang?>&quot; method=&quot;post&quot; onSubmit=&quot;return submitForms();&quot;>

// Sumbit code
<input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;<?php if ($lang == &quot;en&quot;) { ?> Next <? } else { ?> Siguiente <? } ?>&quot;>

// Validation script
<!--

function submitForms(){

if (lang == &quot;en&quot;) {

var error1 = &quot;Please enter your name&quot;;
var error2 = &quot;Please enter your street address&quot;;
var error3 = &quot;Please enter your postcode&quot;;
var error4 = &quot;Please enter your town&quot;;
var error5 = &quot;Please enter your State / County:&quot;;
var error6 = &quot;Please enter your NIF&quot;;
var error7 = &quot;You must provide either a telephone number or an email address&quot;;
var error8 = &quot;Your email address is invalid&quot;;
var error9 = &quot;Please choose your membership type&quot;;

} else {

var error1 = &quot;ES Please enter your name&quot;;
var error2 = &quot;ES Please enter your street address&quot;;
var error3 = &quot;ES Please enter your postcode&quot;;
var error4 = &quot;ES Please enter your town&quot;;
var error5 = &quot;ES Please enter your State / County:&quot;;
var error6 = &quot;ES Please enter your NIF&quot;;
var error7 = &quot;ES You must provide either a telephone number or an email address&quot;;
var error8 = &quot;ES Your email address is invalid&quot;;
var error9 = &quot;ES Please choose your membership type&quot;;

}

if(document.application.name.value == &quot;&quot;) {
alert(error1);
document.application.name.select();
return false;
}

if(document.forms.application.direccion.value == &quot;&quot;) {
alert(error2);
document.application.direccion.select();
return false;
}

if(document.application.codigo_postal.value == &quot;&quot;) {
alert(error3);
document.application.codigo_postal.select();
return false;
}

if(document.application.poblacion.value == &quot;&quot;) {
alert(error4);
document.application.poblacion.select();
return false;
}

if(document.application.provincia.value == &quot;&quot;) {
alert(error5);
document.application.provincia.select();
return false;
}

if ((lang != &quot;en&quot;) && (document.application.nif.value == &quot;&quot;)) {
alert(error6);
document.application.nif.select();
return false;
}

//MAKING EITHER TELEPHONE OR EMAIL MANDATORY
if ((document.application.telefono.value == &quot;&quot;) && (document.application.email.value == &quot;&quot;)) {
alert (error7);
document.application.telefono.select();
return false;
}

//BUT, IF AN EMAIL ADDRESS IS ENTERED IT SHOULD BE CHECKED
if ((document.application.email.value != &quot;&quot;) && (document.application.email.value.indexOf ('@',0) == -1 || document.application.email.value.indexOf ('.',0) == -1)) {
alert (error8);
document.application.email.select();
document.application.email.select();
return false;
}

//WHY DOESN'T THIS WORK?
if ((document.application.cuota[0].checked == false)
&& (document.application.cuota[1].checked == false)
&& (document.application.cuota[2].checked == false)
&& (document.application.cuota[3].checked == false)) {
alert (error9);
return false;
}

}

// -->

 
Error: 'lang' is undefined


Here's a debugging tip in IE: Go to:

Tools >> Internet Options >> Advanced

And check the box that says:

Display a notification about every script error


This way, every time you get an error, it will pop up right away.
bluebrain.gif
blueuniment.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top