p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

proasp_codeclinic thread: SV: Re: jacascript


Message #1 by "Dyrnes, Jan Arve" <jan.arve.dyrnes@f...> on Mon, 3 Sep 2001 13:33:30 +0200
If your "checkForm()" function is attached to the "onClick" event of the
submit button,
then all you need to do is either "return false" for false conditions and
"return true" for
true conditions. Finally, you need to default the function to "return true".
You don't need
a "document.theForm.submit()" call.

Another problem, I see is that you are using a "reserved" word, "name" as a
variable.
Don't do this!!. "Name" is an attribute of many <html> tags. Change "Name"
to "theName"
or some such wording.

Here's my version of your function. Modify to fit your needs.

function checkForm()
{
var okay = true;
var message = "";
if (document.theForm.theName.value == "")
{
    message = message + "Please enter a name.\n";
   okay = false;
}
if (document.theForm.theAns.value == "")
{
   message = message + "Please enter an answer.\n");
   okay = false;
}
if (!okay)
{
   alert(message);
}
return okay;
}

....in the <html> code,

<input type="submit" value="Submit" onClick="return checkForm();">

Please notice the "return checkForm();". The return is required for
Netscape.

Dallas





----- Original Message -----
From: "Dyrnes, Jan Arve" <jan.arve.dyrnes@f...>
To: "Code Clinic" <proasp_codeclinic@p...>
Sent: Monday, September 03, 2001 7:33 AM
Subject: [proasp_codeclinic] SV: Re: jacascript


> It seems like it doesn't run the javascript function at all. If i live a
box
> empty it does not display a alertbox either...
>
> > -----Opprinnelig melding-----
> > Fra: Dallas Martin [SMTP:dmartin@z...]
> > Sendt: 3. september 2001 13:28
> > Til: Code Clinic
> > Emne: [proasp_codeclinic] Re: jacascript
> >
> > Check the status bar at the bottom of your browser window.
> > Do you see an error message?
> >
> >
> >
> > ----- Original Message -----
> > From: "Dyrnes, Jan Arve" <jan.arve.dyrnes@f...>
> > To: "Code Clinic" <proasp_codeclinic@p...>
> > Sent: Monday, September 03, 2001 3:58 AM
> > Subject: [proasp_codeclinic] jacascript
> >
> >
> > > Hello,
> > >
> > > This form is not submited in Netscape 4.7:
> > >
> > > <script language="JavaScript">
> > >
> > > function checkForm()
> > > {
> > >
> > > if (theForm.Name.value == "")
> > > {
> > > alert("Empty name!");
> > > return;
> > > }
> > >
> > > if (theForm.AnsText.value == "")
> > > {
> > > alert("Empty text string!");
> > > return;
> > > }
> > >
> > > // If we've gotten this far, everything's valid!
> > > else
> >
> > > document.theForm.submit();
> > >
> > > }
> > > }
> > >
> > > </script>
> > >
> > >
> > > could any one ples help me out.
> > >
> > > Regards,
> > > Jan Arve

  Return to Index