Solved

select detect impossible?

Posted on 1998-02-02
2
177 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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…

777 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