www.webdeveloper.com
Results 1 to 3 of 3

Thread: Javascript works in IE not in Firefox

  1. #1
    Join Date
    Sep 2010
    Location
    FLORIDA
    Posts
    6

    Javascript works in IE not in Firefox

    The function is supposed to restrict the user from choosing too many categories. The categories are presented as checkboxes. There are two different sets of checkboxes but both validations really do the same thing.

    I have provided the function below and below that the form in its entirety.

    With Internet Explorer the function works as expected. With FF the function allows the user to go to Success.html no matter how many boxes are checked.

    I do have the whole thing set up on a URL but I am not sure if I can post that here.

    I would appreciate any help on this.



    function validate(form) {
    // This function throws a syntax error when saving. It is false and it works. Do not be afraid.
    var totalDes = 0;
    var DesignationsAllowed = 2;
    var max = form1.CheckboxDes.length;
    for (var idx = 0; idx < max; idx++) {
    if (eval("document.form1.CheckboxDes[" + idx + "].checked") == true) {
    totalDes += 1;
    }
    }
    if (totalDes > DesignationsAllowed) {
    alert("You selected " + totalDes + " designations. You are allowed " + DesignationsAllowed);

    return false;}

    var totalSpec = 0;
    var SpecialtiesAllowed = 4;
    var max = form1.CheckboxSpec.length;
    for (var idx = 0; idx < max; idx++) {
    if (eval("document.form1.CheckboxSpec[" + idx + "].checked") == true) {
    totalSpec += 1;
    }
    }
    if (totalSpec > SpecialtiesAllowed) {
    alert("You selected " + totalSpec + " Specialties/Problems. You are allowed " + SpecialtiesAllowed);

    return false;}


    return true;

    }





    <FORM ACTION="Success.html" name="form1" onSubmit="return validate(this.form)">


    <h1>Designations</h1>
    <table align="center" cellpadding="5" cellspacing="5" width="95%">
    <table>


    <tr align="center" valign="top">

    <td>
    <tr>

    <td height="25" valign="middle" width="200" ><input checked name="CheckboxDes" type="checkbox" value="1">
    Consulting<br>
    </td>

    <td height="25" valign="middle" width="200" ><input checked name="CheckboxDes" type="checkbox" value="3">
    Therapist<br>
    </td>

    <td height="25" valign="middle" width="200" ><input checked name="CheckboxDes" type="checkbox" value="2">
    Hypnotist<br>
    </td>

    <td >&nbsp;</td>
    </tr>
    </td>


    </tr>


    <tr align="center" valign="top">

    <td>
    <tr>

    <td height="25" valign="middle" width="200" ><input checked name="CheckboxDes" type="checkbox" value="6">
    Trainer<br>
    </td>

    <td height="25" valign="middle" width="200" ><input name="CheckboxDes" type="checkbox" value="4">
    Practitioner<br>
    </td>

    <td height="25" valign="middle" width="200" ><input name="CheckboxDes" type="checkbox" value="5">
    Stage<br>
    </td>

    <td >&nbsp;</td>
    </tr>
    </td>


    </tr>


    </table>
    </table>

    <h1>Problems</h1>

    <table align="center" cellpadding="5" cellspacing="5" width="80%">
    <table>

    <tr align="center" valign="top">

    <td>
    <tr>

    <td height="25" valign="middle" width="200" ><input name="CheckboxSpec" type="checkbox" value="20">
    5-Path/7-Path<br>
    </td>

    <td height="25" valign="middle" width="200" ><input checked name="CheckboxSpec" type="checkbox" value="26">
    Accelerated Learning
    <br>
    </td>

    <td height="25" valign="middle" width="200" ><input name="CheckboxSpec" type="checkbox" value="27">
    Habits<br>
    </td>

    <td >&nbsp;</td>
    </tr>
    </td>


    </tr>


    <tr align="center" valign="top">

    <td>
    <tr>

    <td height="25" valign="middle" width="200" ><input name="CheckboxSpec" type="checkbox" value="28">
    Anxiety and Stress<br>
    </td>

    <td height="25" valign="middle" width="200" ><input checked name="CheckboxSpec" type="checkbox" value="29">
    Children<br>
    </td>

    <td height="25" valign="middle" width="200" ><input name="CheckboxSpec" type="checkbox" value="30">
    Confidence<br>
    </td>

    <td >&nbsp;</td>
    </tr>
    </td>


    </tr>


    <tr align="center" valign="top" align="80%">

    <td>
    <tr>

    <td height="25" valign="middle" ><input name="CheckboxSpec" type="checkbox" value="31">
    Creativity<br>
    </td>

    <td height="25" valign="middle" ><input name="CheckboxSpec" type="checkbox" value="15">
    Diabetes<br>
    </td>

    <td height="25" valign="middle" ><input name="CheckboxSpec" type="checkbox" value="32">
    Esoteric<br>
    </td>

    <td >&nbsp;</td>
    </tr>
    </td>


    </tr>


    <tr align="center" valign="top">

    <td>
    <tr>

    <td height="25" valign="middle" ><input name="CheckboxSpec" type="checkbox" value="11">
    Fears<br>
    </td>

    <td height="25" valign="middle" ><input name="CheckboxSpec" type="checkbox" value="33">
    Financial<br>
    </td>

    <td height="25" valign="middle" ><input name="CheckboxSpec" type="checkbox" value="21">
    Imagery<br>
    </td>

    <td >&nbsp;</td>
    </tr>
    </td>


    </tr>


    <tr align="center" valign="top">

    <td>
    <tr>

    <td height="25" valign="middle" ><input name="CheckboxSpec" type="checkbox" value="34">
    Health<br>
    </td>

    <td height="25" valign="middle" ><input name="CheckboxSpec" type="checkbox" value="16">
    Birthing<br>
    </td>

    <td height="25" valign="middle" ><input name="CheckboxSpec" type="checkbox" value="14">
    Relationships<br>
    </td>

    <td >&nbsp;</td>
    </tr>
    </td>


    </tr>

    </table>
    </table>
    <div align="center">


    <INPUT TYPE=SUBMIT VALUE="Submit">
    </div>
    </FORM>

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Incorrect referencing. No need to use eval
    Code:
    function validate(form) {
    // This function throws a syntax error when saving. It is false and it works. Do not be afraid.
    var totalDes = 0;
    var DesignationsAllowed = 2;
    var max = document.form1.CheckboxDes.length;
    for (var idx = 0; idx < max; idx++) {
    if (document.form1.CheckboxDes[idx].checked) {
    totalDes += 1;
    }
    }
    if (totalDes > DesignationsAllowed) {
    alert("You selected " + totalDes + " designations. You are allowed " + DesignationsAllowed);
    
    return false;}
    
    var totalSpec = 0;
    var SpecialtiesAllowed = 4;
    var max = document.form1.CheckboxSpec.length;
    for (var idx = 0; idx < max; idx++) {
    if (document.form1.CheckboxSpec[idx].checked) {
    totalSpec += 1;
    }
    }
    if (totalSpec > SpecialtiesAllowed) {
    alert("You selected " + totalSpec + " Specialties/Problems. You are allowed " + SpecialtiesAllowed);
    
    return false;}
    
    
    return true;
    
    }
    At least 98% of internet users' DNA is identical to that of chimpanzees

  3. #3
    Join Date
    Sep 2010
    Location
    FLORIDA
    Posts
    6
    THANK YOU, FANG!!!!

    I have been trying to solve this for SEVERAL hours.

    I sure appreciate your fast and accurate response.

    Dave

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles