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)
Well the thing is: the page change is triggered on a "onchange" 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..
Try this, where all of the SELECT object called "DropDown".
<Script Language="JavaScript">
function checkB()
{
var DropValues=new Array();
var elements=document.all["DropDown"];
var num=document.all["DropDown"].length;
for(n=0;n<num;n++)
{
DropValues[n]=elements[n].options[elements[n].selectedIndex].value;
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->
Put the datas to the value property of the option object as the follows:
...
<option value="Drop1data1=blalbla">Page1</option>
<option value="Drop1data2=blalbla">Page2</option>
...
<option value="Drop2data1=blalbla">Page1</option>
<option value="Drop2data2=blalbla">Page2</option>
...
and bind of them like follow: <Script Language="JavaScript">
function checkB()
{
var DropValues=new Array();
var elements=document.all["DropDown"];
var num=document.all["DropDown"].length;
var page="yourPage.asp?";
for(n=0;n<num;n++)
{
DropValues[n]=elements[n].options[elements[n].selectedIndex].value;
if(n<num-1){
page+=DropValues[n]+"&";
}
}
location.href=page;
}
</Script>
the page object will appear like this:
yourPage.asp?Drop1data2=blabla&Drop2data4=blabla....
OR
you can use the ID property also to get which data belong to which SELECTION.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.