/    Sign up×
Community /Pin to ProfileBookmark

Problem validating my form in NETSCAPE. help!

Hi,
I created a form with javascript validation. It works fine in Internet Explorer, but the validation doesn’t work at all in Netscape or Safari. Help!
Here is the java script::


<script language=”javascript” type=”text/javascript”>

function checkForm(){

if(document.abstract.PrimaryPresenterFirstName.value==””)
{
alert(“Please enter your first name. Thank you!”)
document.abstract.PrimaryPresenterFirstName.focus();
return false
}

if(document.abstract.PrimaryPresenterLastName.value==””)
{
alert(“Please enter your last name. Thank you!”)
document.abstract.PrimaryPresenterLastName.focus();
return false
}

if(document.abstract.TitlePresentation.value==””)
{
alert(“Please enter the title of your presentation. Thank you!”)
document.abstract.TitlePresentation.focus();
return false
}

if(document.abstract.PresentationType[0].checked==false && document.abstract.PresentationType[1].checked==false && document.abstract.PresentationType[2].checked==false){

alert(“Please choose the type of presentation you will be presenting. Thank you.”)
document.abstract.PresentationType[0].focus();
return false
}

if(document.abstract.PrimaryPresenterOrganization.value==””)
{
alert(“Please enter your organization. Thank you!”)
document.abstract.PrimaryPresenterOrganization.focus();
return false
}

if(document.abstract.PrimaryPresenterAddress.value==””)
{
alert(“Please enter your address. Thank you!”)
document.abstract.PrimaryPresenterAddress.focus();
return false
}

if(document.abstract.PrimaryPresenterCity.value==””)
{
alert(“Please enter your city. Thank you!”)
document.abstract.PrimaryPresenterCity.focus();
return false
}

if(document.abstract.PrimaryPresenterCountry.value==””)
{
alert(“Please enter your country. Thank you!”)
document.abstract.PrimaryPresenterCountry.focus();
return false
}

if(document.abstract.PrimaryPresenterTelephone.value==””)
{
alert(“Please enter phone number. Thank you!”)
document.abstract.PrimaryPresenterTelephone.focus();
return false
}

var k=””; var fieldName=””;
var checkStr = “”;
for(k=0;k<4;k++)
{
if (k==0)
{
checkStr = abstract.PrimaryPresenterTelephone.value;
fieldName=”Phone number”;

}

if (k==1) {
checkStr = abstract.PrimaryPresenterFax.value;
fieldName=”Fax Number”;

}

//alert(“fieldName”+fieldName+”—“+k);
var checkOK = “0123456789 -“;

var allValid = true;
var allNum = “”;
var i=””;
for (i = 0; i < checkStr.length; i++)
{
ch = checkStr.charAt(i);
for (j = 0; j < checkOK.length; j++)
if (ch == checkOK.charAt(j))
break;
if (j == checkOK.length)
{
allValid = false;
break;
}
if (ch != “,”)
allNum += ch;
}
if (!allValid)
{
alert(“Please enter only numerals, hyphens or blank spaces in the “+ fieldName +” field.”);
abstract.PrimaryPresenterTelephone.focus();

return (false);
}

}//for

if(document.abstract.PrimaryPresenterEmail.value==””)
{
alert(“Please enter your Email address. Thank you!”)
document.abstract.PrimaryPresenterEmail.focus();
return false
}

elemail=document.abstract.PrimaryPresenterEmail.value;
var elemail3=elemail.indexOf(“@”);
var elemail4=elemail.indexOf(“.”);
if(elemail3==-1 || elemail4==-1)
{
alert(“Please enter a valid E-mail address. Thank you!”)
document.abstract.PrimaryPresenterEmail.focus();
return false
}

var elemail1=elemail.split(“@”);

var elemail2=elemail1[1].split(“.”);

if(elemail1[0]==””||elemail1[1]==””||elemail2[0]==””||elemail2[1]==””){
alert(“Please enter a valid E-mail address. Thank you!”)
document.abstract.PrimaryPresenterEmail.focus();
return false
}

if(document.abstract.PrimaryPresenterEmailConfirm.value==””)
{
alert(“Please confirm your Email address. Thank you!”)
document.abstract.PrimaryPresenterEmailConfirm.focus();
return false
}

if((document.abstract.PrimaryPresenterEmail.value)!=(document.abstract.PrimaryPresenterEmailConfirm.value))
{
alert(“Your email fields don’t match. Please check them. Thank you!”)
document.abstract.PrimaryPresenterEmail.focus();
return false;
}

if(document.abstract.AbstractSummary.value==””)
{
alert(“Please enter a summary of your abstract. Thank you!”)
document.abstract.AbstractSummary.focus();
return false
}

var maxlength=550
if (document.abstract.AbstractSummary.value.length>maxlength){
alert(“Abstract Summary cannot exceed 550 characters, including spaces. Please shorten. Thank you!”)
return false
}

return true;
}

</script>

Here is the Form script:

<form name=”abstract” ACTION=”../_vti_bin/shtml.dll/conference/abstractform_en.html” method=”POST” webbot-action=”–WEBBOT-SELF–” onSubmit=”return checkForm()”>
<!–webbot bot=”SaveResults” S-Email-Format=”TEXT/PRE” S-Email-Address=”[email protected]” startspan –><input TYPE=”hidden” NAME=”VTI-GROUP” VALUE=”0″>
<!–webbot bot=”SaveResults” i-checksum=”43374″ endspan –>
<input type=”reset” name=”Cancel” value=”Cancel” class=”cahsprtxt”>
<input type=”submit” name=”Submit” value=”Submit Abstract” class=”cahsprtxt”>
</form>

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@PittimannFeb 07.2005 — Hi!

There are a couple of things to be done, to get your validation work in Mozilla based browsers:

1) rename your form (abstract is a reserved identifier); let's assume, you rename it 'abstractFrm':

2) replace all instances of 'document.abstract' with 'document.abstractFrm'

3) replace the 'abstract' bits, where you "forgot" the 'document.' prefix (example: abstract.PrimaryPresenterTelephone.focus()? with 'document.abstractFrm'.

Then it should work.

Cheers - Pit
Copy linkTweet thisAlerts:
@CharlesFeb 07.2005 — Make sure that you aren't using HTML 4. HTML 4 doesn't allow the FORM elements to have "name" attributes. Use HTML 4.01 Strrict.
Copy linkTweet thisAlerts:
@moniquecauthorFeb 07.2005 — Thank you very much to Pit and Charles! I will try it out and let you know how it goes.

Moniquec
Copy linkTweet thisAlerts:
@moniquecauthorFeb 07.2005 — Thank you Pit for your advice re: my form in Netscape. It works!!

MoniqueC
Copy linkTweet thisAlerts:
@PittimannFeb 07.2005 — Hi!

You're welcome. ?

Cheers - Pit
×

Success!

Help @moniquec spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...