tags:

views:

135

answers:

3

I have a parent page where a select tag is there. It has a number of options. Now the user can select one of the options.

But the problem is the select tag doesnt have an id instead it has a name which is generated in runtime.

Now i want to fetch the selected value from child page javascript. Can anyone please provide me the pointers for this?

+1  A: 

Given the select element sel, you would get that as follows

var idx=sel.selectedIndex;
var value=sel.options[idx].value;

You could obtain the sel element by giving it an id and using document.getElementById(), or via document.forms['formname'].elements['elementname']

Paul Dixon
Thanks a ton Paul.Can you please also tell me how to fetch the value of the below textarea field in child page javascript?<textarea autopostback="0" title="Object Picker" onkeydown="return onKeyDownRw(this, 'ctl00_m_g_a6d75a1b_8678_47eb_88aa_4ddb5292a25f_ctl00_FormField13_ctl00_ctl00', 3, true, event);" tabindex="1" id="ctl00_m_g_a6d75a1b_8678_47eb_88aa_4ddb5292a25f_ctl00_FormField13_ctl00_ctl00_downlevelTextBox" cols="20" rows="1" name="ctl00$m$g_a6d75a1b_8678_47eb_88aa_4ddb5292a25f$ctl00$FormField13$ctl00$ctl00$downlevelTextBox"/>
archana roy
A: 

Get value of HTML select tag using Javascript--

vae sel = document.get elementbyID("xyz");

alert(sel.options[sel.selectedIndex].text);

archana roy
The OP stated that there isn't an ID (so document.getElementById wouldn't work) and it is document.getElementById not document.get elementbyID.
David Dorward
In fact this is the OP... :-/
Andrzej Doyle
A: 

You are right David. The correct answer is--

Get value of HTML select tag using Javascript--

vae sel = document.getElementsByName("xyz");

alert(sel.options[sel.selectedIndex].text);

archana roy