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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

saving the dropdown value selected

Status
Not open for further replies.

smellykat

Programmer
Mar 4, 2002
33
US
I have an html page - page1 - which has some input fields on it. One is a dropdown list. I need a way to pass/save whatever value was selected in the dropdown, so that when i come back to that page from calling page2, the value is selected.


This is how i am passing the other values of the page:


parent.hidframe.form1.vitem-hold.value="' vitemno '"; parent.hidframe.form1.vqty-hold.value="' vquantity '";


How can I use parent.hidframe for a dropdown? When I use the name of the dropdown like I did for the above 2 fields, I get this error: "parent.hidframe.form1.uomdropdown is not an object."


Thanks.


 
You have to use this:

parent.hidframe.form1.uomdropdown.options[parent.hidframe.form1.uomdropdown.selectedIndex].value;

Instead of that very long statement I'd use this:

dropdown = parent.hidframe.form1.uomdropdown;
and then:
dropdown.options[dropdown.selectedIndex].value

But remember that you cannot assing any new value to select list option this way! It is used only to read the value of the selected option.
 
Ok so I use that statement where? I have my dropdown defined like this:

<select name=&quot;uomlist` i `&quot; TABINDEX=&quot;` (i + 1)`&quot;>

dont I need an onchange or onclick in there to capture the value?
 
Using onchange is the most easy way:

<select ... onchange=&quot;getValue(this.options[this.selectedIndex].value)&quot;>

This way you'll pass the value of selected list item as a parameter of getValue() function.
 
I'm getting a syntax error with this line of code:

eval(&quot;parent.hidframe.form1.uomlist&quot; + i + &quot;.options[parent.hidframe.form1.uomlist&quot; + i + &quot;.selectedIndex].value=' &quot; + document.detailform.uomlist1.options[parent.hidframe.form1.uomlist.selectedIndex].value + &quot; ' &quot;);

the error is :
parent.hidrame.form1.uomlist.selectedIndex is null or not an object
 
It's impossible to tell anything with this piece of code.
 
Lets back up a little. I'm unclear as to what to do in the getvalue() function. Can you clarify?
 
Do there anything you want. You wanted to pass a value to the function? You did it. Then do with it whatever you need:

function getvalue(the_value) {
//example, in case it's numeric:
if (the_value > 20)
{
// do something
}

//example, in case it's literal:
if (the_value != &quot;some string&quot;)
{
// do something else
}
}
 
In the getvalue function, how can I assign the selected dropdown value to a hidden field so that I can pass it to another page?
 
I keep getting the same error when I use this :

parent.hidframe.form1.uomdropdown.options[parent.hidframe.form1.uomdropdown.selectedIndex].value;


I get &quot;parent.hidframe.form1.uomdropdown.options is null or not an object&quot;.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top