0

I have a search application in html with javascript.In that i used select & option(select box).I want to retrieve the values from access database to selectbox.How can i do this with array?i also want to get the count of the option.The below not working correctly.How can i do this.any one knows please help me.Thank you.

var myselect=(selinstal.value);
for(var i=0;i<(select2.option.length);i++)
{
 myarray[i]=myselect;
 rs(myarray); 
 //document.write(rs(0));
}
<select id="Select2" style="width: 152px" name="selinstal">
 <option selected="selected"></option>
</select>
Konamiman
50.5k17 gold badges111 silver badges140 bronze badges
asked Dec 18, 2009 at 11:55

2 Answers 2

1

It can be done by something like this.

I haven't tested it, but it should do..

To get the selected option: document.getElementById("Select2").options[document.getElementById("Select2").selectedIndex].value

To get an array with options: document.getElementById("Select2").options

answered Dec 18, 2009 at 11:59
Sign up to request clarification or add additional context in comments.

4 Comments

How can i replace this code? "for(var i=0;i<(select2.option.length);i++)"
By the exact code i gave you in my answer... ? var options = document.getElementById("Select2").options; then use for(i = 0; i < options.length; i++)
how can i fill values from access database to selectbox in html with javascript?please assist me.me new with javascript.
Try using Google and not just wait here for some working code-samples... some resources... mredkj.com/tutorials/tutorial005.html and google.nl/…
0

Devassy,

Your question is not very clear. If it is how to retrieve the values from access database to selectbox , you should prob do it at the server side code by enumerating the records over the select options.

If it is about how to find the total count of the options for the select, use what Ben has suggested.

document.getElementById("Select2").options.length

Also make sure that the above script executes after the select element is loaded in to the DOM ie after window.onload is invoked.

answered Dec 18, 2009 at 12:45

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.