ASP.NET & Javascript: Setting values from one window to another
I have a child browser window (aspx) opened from the parent application. The child window has some controls, and a textbox. When the user is finished, s/he clicks a button and the following code takes the value from the child window and populates the parent, like so:
window.opener.document.form1.InputContainer$LetterInput$txtReasons.开发者_开发知识库value = txtVal;
This works great for the textbox I have on the parent page. But now, I need to populate a listbox and am not having much luck. I've tried these two methods but to no avail:
o.text = txtVal;
o.value = "1";
window.opener.document.form1.InputContainer$LetterInput$lstReasons.add(o);
window.opener.document.form1.InputContainer$LetterInput$lstReasons.add("Text", "Value");
I get "htmlfile: No such interface supported" with both.
Anybody have any ideas?
Thanks,
Jason
var newOption = document.createElement('option');
newOption.value = textbox.value; // The value that this option will have
newOption.innerHTML = textbox.value; // The displayed text inside of the <option> tags
// Finally, add the new option to the listbox
window.opener.document.form1.InputContainer$LetterInput$lstReasons.appendChild(newOption);
Okay, took a little reworking but found a solution!
First off, create a function in the parent aspx like this:
function NewOption(newVal)
{
//alert("The entry is: " + newVal);
var sel = document.getElementById("<%= MyListbox.clientID %>");
sel.options[sel.options.length]=new Option(newVal, newVal, true, true);
}
Then, call that function from the child page like this:
function SendValues()
{
var txtVal = document.form1.txtReasons.value;
var sel = window.opener.NewOption(txtVal);
}
There's still a kink or two (it only passes the text, not the value) but it that can be easily fixed by adding an extra parameter...
Hopefully someone else out there can use it!
精彩评论