473,322 Members | 1,287 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Getting the selected value of a select input

7
All,

I'm having a little trouble getting the value of a select in my html form. I want a list of dates in a dropdown and when the user clicks on refresh it should do the appropriate action. But when I run in IE7, it comes up with the selectedIndex being undefined.

In my HTML body, I have the select and standard button:

Expand|Select|Wrap|Line Numbers
  1. <body id="example" onload="displayXML();">
  2.     <div class="divPageHeader" style="width: 100%;">
  3.         <select id="dateSelect">
  4.                         <option value="1-Dec-2000">1-Dec-2000</option>
  5.                         <option value="1-Dec-2010">1-Dec-2010</option>
  6.                     </select>
  7.                     <input id="refresh" type="button" value="Refresh" onclick="fnDateChange();" />
  8.     </div>
  9. </body>
  10.  
And in the head, I have the function defined...

Expand|Select|Wrap|Line Numbers
  1. <head>
  2.         <script language="javascript" type="text/javascript">
  3.  
  4.             function fnDateChange() 
  5.             {
  6.                  var selectedDate = document.getElementById("dateSelect").value
  7.                  alert(selectedDate.toString());
  8.                  alert("Index = " + selectedDate.selectedIndex);
  9.                  var oStartDT = selectedDate.options[selectedDate.selectedIndex].value;
  10.  
  11.             }
  12.         }
  13.  
  14.  
  15.     </script>
  16.  
When I run the form, I select the date and click on refresh. And it comes up wit the:

Message box alert with 1-Dec-2010
Message box alert with Index = undefined
Script error

Error: 'options' is null or not an object.
Code: 0
Mar 31 '09 #1
3 8760
acoder
16,027 Expert Mod 8TB
selectedDate should be the select object, not the value, so change line 6 to:
Expand|Select|Wrap|Line Numbers
  1. var selectedDate = document.getElementById("dateSelect");
Mar 31 '09 #2
Andez
7
Yep. Ya beat me to posting the reply cheers...
Mar 31 '09 #3
acoder
16,027 Expert Mod 8TB
Some very old browsers may not accept it, but you could change line 9 to:
Expand|Select|Wrap|Line Numbers
  1. var oStartDT = selectedDate.value;
Will work in probably all modern browsers.
Mar 31 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Dan | last post by:
Can anyone offer suggestions on how to do this or if it is possible? I have a form that uses a drop down box and 2 text fields. What I am trying to do is have the value of each text box set by...
8
by: McKirahan | last post by:
Firefox does not reflect selected option via innerHTML How do I get Firefox to reflect selected option values? <html> <head> <title>FFinner.htm</title> <script type="text/javascript">...
1
by: bagya | last post by:
please help me out the following is the small code i have <html> <head> <script type="text/javascript"> function validate() { if (document.abc.region.value==0)
1
by: simbarashe | last post by:
Hie could someone please help me with getting and using the current page url. I have a function that gets the url, I want to use it with header(location : XXX) but it wont work. The code is as...
4
by: jeet | last post by:
Plz help me.Problem is that On the first page I display all other user with checkbox and give user option to select only two user which he wants to send message. Tell me please how I'll get those...
10
by: patsman77 | last post by:
I hope this is the right spot to post this.... I am working on a form to pull the information from the database. I am trying to use arrays, but I only get one record to come back and it is...
1
by: angelicdevil | last post by:
i have listbox 1 which displays status , based on selection of status listbox 2 displays usernames. and based on username selected the textbox displays the email id. its working fine till...
9
Catalyst159
by: Catalyst159 | last post by:
I have a form which is used to calculate residential Floor Area Ratio (FAR). The form is structured into seven parts as follows: Part A: Maximum FAR and Floor Area: Part B: Gross Floor Area of...
9
vikas251074
by: vikas251074 | last post by:
I am not getting date value in spite of my good effort. This code was working in my last office where I work. Now I am trying to work at my home pc. but not getting date value. Any can help me why...
7
vikas251074
by: vikas251074 | last post by:
I am getting error above in following code since few days giving tension day and night. How can I solve this? I am facing since Oct.25. in line no. 362 After doing a lot of homework, I am...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.