Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to read dropdownboxes

Status
Not open for further replies.

JohnSwe

Programmer
Feb 20, 2001
14
SE
Hi!

How do i read dropdown boxes and send the results in quesry string when using the "location.href" to change url for the user without having a submit button?
 
use onchange() to fire the function
use form.dropdown.options[form.dropdown.SelectedIndex].value or .text to get the value or the text of the selected line
pass the values with the url (yourpage.htm?param1=val1)
 
Hi.

Here is a really simple example to use dropdown and location.href:

<html>
<Script Language=&quot;JavaScript&quot;>

function selected()
{
var page=document.all.sel.options[document.all.sel.selectedIndex].value;
location.href=page;
}
</Script>
<body>
<select name=&quot;sel&quot; id=&quot;sel&quot; size=1 onchange=&quot;selected()&quot;>
<option value=&quot;&quot; selected>none</option>
<option value=&quot;page1.asp?data1=blalbla&quot;>Page1</option>
<option value=&quot;page2.asp?data2=blalbla&quot;>Page2</option>
<option value=&quot;page3.asp?data3=blalbla&quot;>Page3</option>
</select>
</body>
</html>


regards, Kirilla
 
Well the thing is: the page change is triggered on a &quot;onchange&quot; in another dropdown menu. And when that happens I want to read the values in all the dropdown boxes and send those values along with the querystring..

is that possible? :)
 
Hi.

Try this, where all of the SELECT object called &quot;DropDown&quot;.

<Script Language=&quot;JavaScript&quot;>

function checkB()
{
var DropValues=new Array();
var elements=document.all[&quot;DropDown&quot;];
var num=document.all[&quot;DropDown&quot;].length;
for(n=0;n<num;n++)
{
DropValues[n]=elements[n].options[elements[n].selectedIndex].value;

}
}
</Script>



regards, Kirilla
 
Thanks Krilla!

But how do i no what data comes from what box?
(I mean on the page that the user gets redirected to?)

The page that is redirected to is an asp page where i want to store the users chioces as session varialbles. So i need to no what value came from what box. 8->
 
Hi.

Put the datas to the value property of the option object as the follows:

...
<option value=&quot;Drop1data1=blalbla&quot;>Page1</option>
<option value=&quot;Drop1data2=blalbla&quot;>Page2</option>
...
<option value=&quot;Drop2data1=blalbla&quot;>Page1</option>
<option value=&quot;Drop2data2=blalbla&quot;>Page2</option>
...
and bind of them like follow:
<Script Language=&quot;JavaScript&quot;>

function checkB()
{
var DropValues=new Array();
var elements=document.all[&quot;DropDown&quot;];
var num=document.all[&quot;DropDown&quot;].length;
var page=&quot;yourPage.asp?&quot;;
for(n=0;n<num;n++)
{
DropValues[n]=elements[n].options[elements[n].selectedIndex].value;
if(n<num-1){
page+=DropValues[n]+&quot;&amp;&quot;;
}
}
location.href=page;
}
</Script>


the page object will appear like this:
yourPage.asp?Drop1data2=blabla&amp;Drop2data4=blabla....

OR

you can use the ID property also to get which data belong to which SELECTION.

regards, Kirilla
 

Hmm but ie tells me that:

&quot;document.all[&quot;DropDown&quot;].length is not an object..&quot; :/

What am I doing wrong?
 
Hi.

1. All SELECT object have to called &quot;DropDown&quot;.
<SELECT name=&quot;DropDown&quot; .....>
<Option ....
</Select>
....

If it doesn't work, may be you misstyped something.
(if not, send me your source and I'll try to give answer.)
tibor.kircsi@scala.hu

regards, Kirilla
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top