How do I obtain the value of Select?

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

    How do I obtain the value of Select?

    I have a select tag as follows

    <SELECT ID="Select1" NAME="Select1" ONCHANGE="do_al ert()">
    <OPTION>1</OPTION>
    <OPTION>2</OPTION>
    </SELECT>

    I need, when the user choose an option, to print an alert
    which displays the text in the option chosen, i.e. 1 or 2
    in this example, but how do I access the value of the html
    select tag, I tried

    alert(document. getElementById( 'Select1').valu e);

    But this seems to be an empty alert box. Any ideas what might I be
    doing wrong?

    Tia


  • Jukka K. Korpela

    #2
    Re: How do I obtain the value of Select?

    html wrote:
    I have a select tag as follows
    >
    <SELECT ID="Select1" NAME="Select1" ONCHANGE="do_al ert()">
    <OPTION>1</OPTION>
    <OPTION>2</OPTION>
    </SELECT>
    HTML-wise (i.e., from the perspective we are supposed to have in this
    group), that construct has more problems than I care to list down. This is
    probably not your _real_ select element, is it?
    I need, when the user choose an option, to print an alert
    which displays the text in the option chosen,
    That's external to HTML, of course, hence off-topic in this group. Your use
    of the fake name "html" does not change that.
    but how do I access the value of the html
    select tag, I tried
    >
    alert(document. getElementById( 'Select1').valu e);
    We could tell you, but that would be off-topic and would teach you wrong
    habits, like posting to a wrong group and not reading the fine manual. So
    consider reading a tutorial on the basics of an introduction to the elements
    of JavaScript in the web context before trying to use JavaScript on the web.

    --
    Yucca, http://www.cs.tut.fi/~jkorpela/

    Comment

    • Jonathan N. Little

      #3
      Re: How do I obtain the value of Select?

      Jukka K. Korpela wrote:
      html wrote:
      >
      >I have a select tag as follows
      >>
      ><SELECT ID="Select1" NAME="Select1" ONCHANGE="do_al ert()">
      ><OPTION>1</OPTION>
      ><OPTION>2</OPTION>
      ></SELECT>
      >
      HTML-wise (i.e., from the perspective we are supposed to have in this
      group), that construct has more problems than I care to list down. This
      is probably not your _real_ select element, is it?
      >
      >I need, when the user choose an option, to print an alert
      >which displays the text in the option chosen,
      >
      That's external to HTML, of course, hence off-topic in this group. Your
      use of the fake name "html" does not change that.
      >
      >but how do I access the value of the html
      >select tag, I tried
      >>
      >alert(document .getElementById ('Select1').val ue);
      >
      We could tell you, but that would be off-topic and would teach you wrong
      habits, like posting to a wrong group and not reading the fine manual.
      So consider reading a tutorial on the basics of an introduction to the
      elements of JavaScript in the web context before trying to use
      JavaScript on the web.
      >
      As I recall MSIE will not automatically transfer the enclosed content of
      an option element to its value attribute. You must implicitly define it
      in your markup:
      <SELECT ID="Select1" NAME="Select1"
      ONCHANGE="alert (document.getEl ementById('Sele ct1').value)">
      <OPTION VALUE="1">1</OPTION>
      <OPTION VALUE="2">2</OPTION>
      </SELECT>


      --
      Take care,

      Jonathan
      -------------------
      LITTLE WORKS STUDIO

      Comment

      • Lars Eighner

        #4
        Re: How do I obtain the value of Select?

        In our last episode, <48dd055a$1_3@m k-nntp-2.news.uk.tisca li.com>, the
        lovely and talented html broadcast on comp.infosystem s.www.authoring.html:
        I have a select tag as follows

        The answer is the same as the last time you posted this.

        --
        Lars Eighner <http://larseighner.com/usenet@larseigh ner.com
        This would be the best of all possible worlds,
        if there were no religions in it. -- John Adams

        Comment

        Working...