<OPTION> Tag and Values

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Craig Keightley

    #1

    <OPTION> Tag and Values

    How do I retrive the Name of the item in a select box

    I have the following form
    <select name="select">
    <option value="1">Monda y</option>
    <option value="2">Tuesd ay</option>
    <option value="3">Wedne sday</option>
    <option value="4">Thurs day</option>
    </select>

    I have a button on the page that i want to alert a message when an item in
    the select box has been chosen

    eg If Monday was chosen (value 1), the alert should read You selected Monday


    Many Thanks

    Craig


  • Lee

    #2
    Re: &lt;OPTION&g t; Tag and Values

    Craig Keightley said:[color=blue]
    >
    >How do I retrive the Name of the item in a select box
    >
    >I have the following form
    > <select name="select">
    > <option value="1">Monda y</option>
    > <option value="2">Tuesd ay</option>
    > <option value="3">Wedne sday</option>
    > <option value="4">Thurs day</option>
    > </select>
    >
    >I have a button on the page that i want to alert a message when an item in
    >the select box has been chosen
    >
    >eg If Monday was chosen (value 1), the alert should read You selected Monday[/color]

    What you're calling the "Name" is the "text" attribute of the
    selected option.

    So you would use the method describe in the FAQ, but substitute
    "text" for "value":


    Comment

    • Randy Webb

      #3
      Re: &lt;OPTION&g t; Tag and Values

      Craig Keightley wrote:[color=blue]
      > How do I retrive the Name of the item in a select box
      >
      > I have the following form
      > <select name="select">
      > <option value="1">Monda y</option>
      > <option value="2">Tuesd ay</option>
      > <option value="3">Wedne sday</option>
      > <option value="4">Thurs day</option>
      > </select>
      >
      > I have a button on the page that i want to alert a message when an item in
      > the select box has been chosen
      >
      > eg If Monday was chosen (value 1), the alert should read You selected Monday[/color]

      <script type="text/javascript">
      function showText(){
      el=document.for ms['myForm'].elements['mySelect'];

      //get the current selections index
      elIndex = el.selectedInde x;

      //get the current selections text
      elText = el.options[elIndex].text;

      alert('Since you, as the user, are too stupid, blind or ignorant ' +
      'to look at the select list you just changed, I find it, as the ' +
      'author, to give you an annoying alert box to let you know you chose ' +
      elText)
      }
      </script>
      <form name="myForm">
      <select name="mySelect" >
      <option value="1">Monda y</option>
      <option value="2">Tuesd ay</option>
      <option value="3">Wedne sday</option>
      <option value="4">Thurs day</option>
      </select>
      <input type="button" onclick="showTe xt()" value="Show Me">



      --
      Randy
      comp.lang.javas cript FAQ - http://jibbering.com/faq

      Comment

      Working...