Solved

select detect impossible?

Posted on 1998-02-02
2
186 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

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 …
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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…

705 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