Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Mar 2008
    Posts
    24
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Anything wrong with this switch?

    I have this switch in a function that is called by an event. I don't see anything wrong with it, but when I add it to a script that's already in the head section of the page, all of the page's event functions give me errors. So without this switch, everything works, and with the switch, nothing works. Where's my error?

    PHP Code:
    function evaluateoption()
    {
    switch()
    {
    case 
    10:
    choose10();
    break;
    case 
    13:
    choose13();
    break;
    case 
    14:
    choose14();
    break;
    case 
    21:
    choose21();
    break;
    case 
    30:
    choose30();
    break;
    case 
    38:
    choose38();
    break;
    case 
    43:
    choose43();
    break;
    case 
    44:
    choose44();
    break;
    case 
    47:
    choose47();
    break;
    case 
    51:
    choose51();
    break;
    case 
    57:
    choose57();
    break;
    case 
    62:
    choose62();
    break;
    case 
    72:
    choose72();
    break;
    case 
    73:
    choose73();
    break;
    case 
    81:
    choose81();
    break;
    case 
    99:
    choose99();
    break;
    case 
    103:
    choose103();
    break;
    case 
    105:
    choose105();
    break;
    case 
    107:
    choose107();
    break;
    case 
    138:
    choose138();
    break;
    case 
    150:
    choose150();
    break;
    case 
    153:
    choose153();
    break;
    case 
    160:
    choose160();
    break;
    case 
    167:
    choose167();
    break;
    case 
    170:
    choose170();
    break;
    case 
    171:
    choose171();
    break;
    case 
    176:
    choose176();
    break;
    case 
    195:
    choose195();
    break;
    case 
    203:
    choose203();
    break;
    case 
    204:
    choose204();
    break;
    case 
    215:
    choose215();
    break;
    case 
    222:
    choose222();
    break;
    case 
    223:
    choose223();
    break;
    case 
    225:
    choose225();
    break;
    case 
    229:
    choose229();
    break;
    }


  • #2
    Regular Coder ninnypants's Avatar
    Join Date
    Apr 2008
    Location
    Utah
    Posts
    504
    Thanks
    10
    Thanked 47 Times in 47 Posts
    You need something to compare the cases to
    Code:
    switch()// put something in the parentheses like a variable

  • #3
    New Coder
    Join Date
    Mar 2008
    Posts
    24
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Suppose I put a dead variable like switch(x) where x isn't defined and the following in the HTML:

    PHP Code:
    <select name="list" onchange="evaluateoption(this.value);">
    <
    option value="10">Number 10</option>
    <
    option value="13">Number 13</option>
    </
    select
    Would that work?

  • #4
    Regular Coder ninnypants's Avatar
    Join Date
    Apr 2008
    Location
    Utah
    Posts
    504
    Thanks
    10
    Thanked 47 Times in 47 Posts
    Yeah it should as long as your function looks like this
    Code:
    function evaluateoption(x)
    {
    switch(x)

  • #5
    New Coder
    Join Date
    Mar 2008
    Posts
    24
    Thanks
    2
    Thanked 0 Times in 0 Posts
    That solved it. Thanks.


  •  

    Posting Permissions

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