Help - Search - Members - Calendar
Full Version: Script works in IE, Not in FF
HTMLHelp Forums > Programming > Client-side Scripting
philwinter
Perhaps someone can offer some assistance with some Javascript I placed in a web page. The purpose is to ensure that content has been entered in certain fields of an email form. This was done to avoid getting empty forms if someone clicks Submit without entering anything. Instead, they will be prompted to enter the required fields. I don't think this is a problem of a pop-up being blocked by FF because I get no alert that a pop-up is being blocked.

The Javascript code is:

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

<!-- hide script from older browsers
function validateForm(contact)
{

if(""==document.forms.contact.LastName.value)
{
alert("Please enter your last name.");
return false;
}

if(""==document.forms.contact.email.value)
{
alert("Please enter your email address.");
return false;
}

if(""==document.forms.contact.questions.value)
{
alert("Please enter your question or comment.");
return false;
}

}
stop hiding script -->
</script>


The <form> tag is :
<form name="contact" method="post" action="_gdForm/webformmailer.asp"
onSubmit="return validateForm(contact);">


Thanks in advance for your help.
Christian J
QUOTE(philwinter @ May 13 2009, 07:08 PM) *

I don't think this is a problem of a pop-up being blocked by FF because I get no alert that a pop-up is being blocked.

Correct, popup blockers don't block alert boxes.

In the script, try adding a "return true" after the last IF condition.

----------

Probably just side-notes:

CODE
onSubmit="return validateForm(contact);

Since the function doesn't use the "contact" parameter in the function call, you might as well remove it:

CODE

function validateForm()

...

onSubmit="return validateForm();

If you did use it, it should be quoted:

CODE
onSubmit="return validateForm('contact');
pandy
QUOTE(Christian J @ May 13 2009, 09:48 PM) *

If you did use it, it should be quoted:

CODE
onSubmit="return validateForm('contact');



So should that. tongue.gif

CODE
onsubmit="return validateForm('contact');"
philwinter
Hi Pandy and Christian, Unfortunately, the changes you suggested didn't work. Of course, I may have made an error entering them - I know nothing about JavaScript, so I may have placed the statement in the wrong place or have the syntax wrong. FF still sends the empty form.

Here's the modified code.

<!-- hide script from older browsers
function validateForm(contact)
{

if(""==document.forms.contact.LastName.value)
{
alert("Please enter your last name.");
return false;
}

if(""==document.forms.contact.email.value)
{
alert("Please enter your email address.");
return false;
}

if(""==document.forms.contact.questions.value)
{
alert("Please enter your question or comment.");
return false;
}
return true;
}
stop hiding script -->
</script>


And the <form> tag.

<form name="contact" method="post" action="_gdForm/webformmailer.asp"
onSubmit="return validateForm();">
Christian J
QUOTE(philwinter @ May 13 2009, 11:00 PM) *

FF still sends the empty form.

This part:

CODE
stop hiding script -->

needs a "//" before, if it's used at all (using HTML comments to hide from old browsers is not necessary anymore, since the browsers in question are long gone). So try something like:

CODE
<script type="text/javascript">
function validateForm()
{
    if(""==document.forms.contact.LastName.value)
    {
        alert("Please enter your last name.");
        return false;
    }

    if(""==document.forms.contact.email.value)
    {
        alert("Please enter your email address.");
        return false;
    }

    if(""==document.forms.contact.questions.value)
    {
        alert("Please enter your question or comment.");
        return false;
    }
    return true;
}
</script>
Christian J
QUOTE(pandy @ May 13 2009, 10:02 PM) *

So should that. tongue.gif

It was a minimal test case! angry.gif
Frederiek
Excuse me, but shouldn't the following not be the other way around?

not:
if(""==document.forms.contact.LastName.value)

but:
if(document.forms.contact.LastName.value=="")

etc.
Christian J
QUOTE(Frederiek @ May 14 2009, 09:33 AM) *

Excuse me, but shouldn't the following not be the other way around?

not:
if(""==document.forms.contact.LastName.value)

but:
if(document.forms.contact.LastName.value=="")

etc.

I don't think it matters in this case (and my browsers agree), but I haven't found any specs saying so.

With other operators like "=" or "<" the order does matter, of course.
Brian Chandler
QUOTE(Christian J @ May 14 2009, 08:54 PM) *

QUOTE(Frederiek @ May 14 2009, 09:33 AM) *

Excuse me, but shouldn't the following not be the other way around?

not:
if(""==document.forms.contact.LastName.value)

but:
if(document.forms.contact.LastName.value=="")

etc.

I don't think it matters in this case (and my browsers agree), but I haven't found any specs saying so.

With other operators like "=" or "<" the order does matter, of course.



It looks very funny, but equality is commutative. A=B iff B=A. (That's the = of logic, of course, not the (inappropriate, IMO) assignment operator.) I suppose in principle one could design a programming language in which equality was (subtly) non-commutative, but it doesn't sound very likely.
philwinter
Christian, that seems to have been the problem. I removed the HTML comment tags and the script works fine in FF now. Thanks so much for your help. And thanks to everyone who offered help with this simple problem. This is a great forum, particularly for dummies like me who sometimes get in over our heads!
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.