Using select option values in function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Abby Lee

    Using select option values in function

    I want to check the value for a dropdown menu for "other" to make it
    so they can add a location that is not on the list.
    If the value = "other" I will bring up a dilog box they can enter
    their location...I have replaced this with an alert for testing...it
    does not work. What am I missing?

    <head>
    <script language="JavaS cript">
    function location(s)
    {
    var v = s.options[s.selectedIndex];
    if (v.value=="othe r")
    alert("works");
    }
    </script>
    </head>
    <body>
    <form><select name="location" size="1" onChange="locat ion(this)">
    <option value=" "></option>
    <option value="Access"> Access</option>
    <option value="BI">BI</option>
    <option value="CAB">CAB </option>
    <option value="Durst">D urst</option>
    <option value="OCB">OCB </option>
    <option value="SRP">SRP </option>
    <option value="Trecc">T recc</option>
    <option value="other">o ther</option>
    </select></form>
    </body>
  • kaeli

    #2
    Re: Using select option values in function

    In article <80504bef.04070 91126.591a9228@ posting.google. com>, abbylee26
    @hotmail.com enlightened us with...[color=blue]
    > I want to check the value for a dropdown menu for "other" to make it
    > so they can add a location that is not on the list.
    > If the value = "other" I will bring up a dilog box they can enter
    > their location...I have replaced this with an alert for testing...it
    > does not work. What am I missing?
    >[/color]

    The fact that you've basically got three things called "location". Your
    select, your function, and the intrinsic location object.

    This worked fine. All I changed were the names and I added the type
    attribute (language is deprecated).

    <html>
    <head>
    <script language="JavaS cript" type="text/javascript">
    function f_location(s)
    {
    var v = s.options[s.selectedIndex];
    if (v.value=="othe r")
    alert("works");
    }
    </script>
    </head>
    <body>
    <form><select name="s_locatio n" size="1" onChange="f_loc ation(this)">
    <option value=" "></option>
    <option value="Access"> Access</option>
    <option value="BI">BI</option>
    <option value="CAB">CAB </option>
    <option value="Durst">D urst</option>
    <option value="OCB">OCB </option>
    <option value="SRP">SRP </option>
    <option value="Trecc">T recc</option>
    <option value="other">o ther</option>
    </select></form>
    </body>
    </html>


    --
    --
    ~kaeli~
    A midget fortune teller who escapes from prison is a small
    medium at large.



    Comment

    • Lee

      #3
      Re: Using select option values in function

      Abby Lee said:[color=blue]
      >
      >I want to check the value for a dropdown menu for "other" to make it
      >so they can add a location that is not on the list.
      >If the value = "other" I will bring up a dilog box they can enter
      >their location...I have replaced this with an alert for testing...it
      >does not work. What am I missing?
      >
      ><head>
      ><script language="JavaS cript">
      >function location(s)[/color]

      Probably the fact that "location" is a reserved word.
      Change the name of your function (both places).

      Comment

      • Abby Lee

        #4
        Re: Using select option values in function

        Lee <REM0VElbspamtr ap@cox.net> wrote in message news:<ccmuhk0o5 o@drn.newsguy.c om>...[color=blue]
        > Abby Lee said:[color=green]
        > >
        > >I want to check the value for a dropdown menu for "other" to make it
        > >so they can add a location that is not on the list.
        > >If the value = "other" I will bring up a dilog box they can enter
        > >their location...I have replaced this with an alert for testing...it
        > >does not work. What am I missing?
        > >
        > ><head>
        > ><script language="JavaS cript">
        > >function location(s)[/color]
        >
        > Probably the fact that "location" is a reserved word.
        > Change the name of your function (both places).[/color]

        No,
        I actully changed the code to be more readable for you.
        My code does not work with the original function name of "BuildLoc"

        Comment

        • Lee

          #5
          Re: Using select option values in function

          Abby Lee said:[color=blue]
          >
          >Lee <REM0VElbspamtr ap@cox.net> wrote in message[/color]
          [color=blue][color=green]
          >> Probably the fact that "location" is a reserved word.
          >> Change the name of your function (both places).[/color]
          >
          >No,
          >I actully changed the code to be more readable for you.
          >My code does not work with the original function name of "BuildLoc"[/color]

          Posting a simplified example is a good idea, but you've
          got to make sure that the example that you post shows
          the same errors that you're asking about, and no new ones.

          Comment

          • Abby Lee

            #6
            Re: Using select option values in function

            Lee <REM0VElbspamtr ap@cox.net> wrote in message news:<ccro9a0n0 b@drn.newsguy.c om>...[color=blue]
            > Abby Lee said:[color=green]
            > >
            > >Lee <REM0VElbspamtr ap@cox.net> wrote in message[/color]
            >[color=green][color=darkred]
            > >> Probably the fact that "location" is a reserved word.
            > >> Change the name of your function (both places).[/color]
            > >
            > >No,
            > >I actully changed the code to be more readable for you.
            > >My code does not work with the original function name of "BuildLoc"[/color]
            >
            > Posting a simplified example is a good idea, but you've
            > got to make sure that the example that you post shows
            > the same errors that you're asking about, and no new ones.[/color]


            I must apologize, I made your corrections in my edited (easy to read)
            code and it still did not work. I just cut and pasted your code and it
            works.

            Thank you Lee and Kaeli for your help on this.

            Comment

            Working...