Web Analytics Made Easy -
StatCounter numbers in switch statements - CodingForum

Announcement

Collapse
No announcement yet.

numbers in switch statements

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • numbers in switch statements

    I have a method of Javascript that has errors, but I can't figure out what is wrong.
    I have Perl script generating a Select and this javascript method, when the Select is filled with names the code works fine but if it is filled with numbers I get errors in the corrisponding javascript.
    <td>
    <select name='stprPart' onChange='return jsSel(this.form, this);'>
    <option selected value="1234">--new part--</option>
    <option value="10000101">10000101</option>
    <option value="10000102">10000102</option>
    <option value="90070040-1">90070040-1</option>
    </select>
    </td>
    <script>
    function jsSel(formL, obj) {
    switch(obj.value+''){
    case "10000101": { formL.ptPartNum.value = '10000101';
    formL.ptActive.value = 'TRUE';
    break;}
    case "10000102": { formL.ptPartNum.value = '10000102;
    formL.ptActive.value = 'TRUE';
    break;}
    case "90070040-1": { formL.ptPartNum.value = '90070040-1;
    formL.ptActive.value = 'TRUE';
    break;}
    }
    return false;
    }
    </script>

    When I switch on names and not numbers I get no errors.
    thanks.

  • #2
    edit just noticed
    formL.ptPartNum.value = '90070040-1;
    should be
    formL.ptPartNum.value = '90070040-1';

    tested this with IE6 MozFF

    NO problem

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
    
    <html>
    
    <head>
      <title></title>
    </head>
    
    <body>
    <select name='stprPart' onChange='return jsSel(this.form, this);'>
    <option selected value="1234">--new part--</option>
    <option value="10000101">10000101</option>
    <option value="10000102">10000102</option>
    <option value="90070040-1">90070040-1</option>
    </select>
    </td>
    <script>
    function jsSel(formL, obj) {
    switch(obj.value){
    case '10000101': {
    alert('10000101');
    break;}
    case '10000102': {
    alert('10000102');
    break;}
    case '90070040-1': {
    alert('90070040-1');
    break;}
    }
    return false;
    }
    </script>
    
    </body>
    
    </html>
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/

    Comment


    • #3
      thanks

      it was a problem with quotes, but the ones you fixed weren't the problem (I miss typed the code that time). Thanks.

      Comment

      Working...
      X