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

javascript works in IE but not firefox

Status
Not open for further replies.

gog8trs

Programmer
Mar 25, 2006
5
US
i have a coldfusion form that i built using javascript to delegate the required fields in the form. it works fine in IE, but firefox does not accept the javascript. im not sure whether or not its related to the form. heres an exmaple of what i am using for the javascript:

Code:
<script language="javascript">
function validate_form ( )
{
    valid = true;

    if ( ( document.signup.name.value == "" ) )
    {
        alert ( "Name is empty!" );
        valid = false;
    }
	else if ( ( document.signup.company.value == "" ) )
    {
        alert ( "Company is empty!" );
        valid = false;
    }
    return valid;
}
 
First of all, that question belongs in the JS forum because there no CF code involved in the JS function.

Second of all, I don't think you need the double-parenthesis in the if-statements.

See if this works:
Code:
<script language="javascript">
function validate_form ()
{
    [COLOR=red]var[/color] valid = true;

    if (document.signup.name.value == "") {
        alert("Name is empty!");
        valid = false;
    }
    
    if (document.signup.company.value == "") {
        alert("Company is empty!");
        valid = false;
    }

    return valid;
}
</script>

_____________________________
Just Imagine.
 
hhhmmm ok. well i tried what you offered and im getting the same result. any other ideas? thanks in advance
 
I just put this together (as an HTML file) and ran it in FF, and I get the JS alerts fine.

Code:
<html>
<head>

<script language="javascript">
function validate_form ()
{
    var valid = true;

    if (document.signup.name.value == "") {
        alert("Name is empty!");
        valid = false;
    }
    
    if (document.signup.company.value == "") {
        alert("Company is empty!");
        valid = false;
    }

    return valid;
}
</script>
</head>

<body>
<form name="signup" onSubmit="return validate_form();">
<input type="text" name="name"> name <br/>
<input type="text" name="company"> company <br/>
<input type="submit" name="submit">
</form>
</body>
</html>

Is there any other JS function that might cause it to fail? Do what cfSearching just suggested or use firebug to see the errors

_____________________________
Just Imagine.
 
thanks for both of your help. i tried looking at the error console and nothing is relevant to javascript. not sure if this would help but take a look at my code:
Code:
<script language="javascript">
function validate_form ( )
{
    valid = true;

    if ( ( document.forms['signup'].elements['name'].value == "" ) )
    {
        alert ( "Name is empty!" );
        valid = false;
    }
    else if ( ( document.forms['signup'].elements['company'].value == "" ) )
    {
        alert ( "Company is empty!" );
        valid = false;
    }
    else if ( ( document.forms['signup'].elements['job_title'].value == "" ) )
    {
        alert ( "Job Title is empty!" );
        valid = false;
    }
    else if ( ( document.forms['signup'].elements['address'].value == "" ) )
    {
        alert ( "Address is empty!" );
        valid = false;
    }
    else if ( ( document.forms['signup'].elements['city'].value == "" ) )
    {
        alert ( "City is empty!" );
        valid = false;
    }
    else if ( ( document.forms['signup'].elements['state'].value == "" ) )
    {
        alert ( "State is empty!" );
        valid = false;
    }
    else if ( ( document.forms['signup'].elements['zip'].value == "" ) )
    {
        alert ( "Zip Code is empty!" );
        valid = false;
    }
    else if ( ( document.forms['signup'].elements['phone'].value == "" ) )
    {
        alert ( "Phone Number is empty!" );
        valid = false;
    }
    else if ( ( document.forms['signup'].elements['email'].value == "" ) )
    {
        alert ( "Email Address is empty!" );
        valid = false;
    }
    else if ( ( document.forms['signup'].elements['request'].value == "0" ) )
    {
        alert ( "Request is empty!" );
        valid = false;
    }
    else if ( ( document.forms['signup'].elements['area_of_interest'].value == "0" ) )
    {
        alert ( "Area of Interest is empty!" );
        valid = false;
    }
    else if ( ( document.forms['signup'].elements['comments'].value == "" ) )
    {
        alert ( "Comments is empty!" );
        valid = false;
    }


    return valid;
}

</script>
<body>
<form name="signup" method="post" onSubmit="return validate_form ( );">
<input name="name" type="text" id="name">
<input name="company" type="text" id="company">
<input name="job_title" type="text" id="job_title">
<input type="submit" name="Submit" value="Submit">
</form>
</body>
</html>
 
I just copied/pasted what you just posted and ran this in FF, and it works. Do you have a URL you can show us so we can see the issue in person?

Is there any other code/JS function that might cause it to fail? What did you see when you ran firebug?

_____________________________
Just Imagine.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top