Solved

select detect impossible?

Posted on 1998-02-02
2
181 Views
Last Modified: 2008-03-06
I have a select box (drop down list) on my html form. Is it possible to detect which one of the options is currently selected BEFORE the user presses the submit button using javascript??
e.g. The select box contains the following, choice1,choice2,choice3,choice4. each of the choices has a value associated with it:£5,£10,£15,£20. I also have a text box which I want to populate with the value according to which choice from the select box is currently selected. so, if the choose choice1, the text box is updated to display £5. I was thinking of catching the ONBLUR or ONCHANGE event of the select box to call a javascript function which populates the text box with: selectbox.option.selected, or even looping through each of the options to see which one had its selected property set, but it doesn't work. Is there any way to do this? (using ie.3 and netscape 3)
cheers for any suggestions.
0
Comment
Question by:acsmith
2 Comments
 
LVL 5

Accepted Solution

by:
julio011597 earned 20 total points
ID: 1277946
I guess the problem is in your "selectbox.option.selected" which just checks for an option named "option" to be selected.

Here is a sample:

--//--
<HTML>
  <HEAD>
    <SCRIPT LANGUAGE="JavaScript1.1"><!--
      function selectChange(aSelect, aText) {
        aText.value = aSelect.options[aSelect.selectedIndex].text;
        return true;
      }
    // --></SCRIPT>
  </HEAD>
  <BODY>
    <FORM NAME="theForm">
      <INPUT TYPE="text" NAME="theText" VALUE="£5">
      <SELECT NAME="theSelect" onChange="JavaScript:selectChange(theSelect, theText);">
        <OPTION VALUE="0" SELECTED>£5
        <OPTION VALUE="1">$10
        <OPTION VALUE="2">&15
        <OPTION VALUE="3">&20
      </SELECT>
    </FORM>
  </BODY>
</HTML>
--//--

HTH, julio
0
 
LVL 1

Author Comment

by:acsmith
ID: 1277947
thankyou!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Button and js nou working 3 19
jQuery on Submit 4 36
Filktering Alphabetically 8 28
How  can  I extract  Id  from a  URL  using  Javascript? 12 29
In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question