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

Moving values from one window to another

Status
Not open for further replies.

dBjason

Programmer
Mar 25, 2005
355
0
0
US
I have a child window (aspx page) opened from the parent application (using window.open). 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's textbox 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 on the parent 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? If I've posted in the wrong place please let me know so I can move it to a different forum.

Thanks,

Jason
 
Hi

Try this :
JavaScript:
window[teal].[/teal]opener[teal].[/teal]document[teal].[/teal]form1[teal].[/teal]InputContainer$LetterInput$lstReasons[teal].[/teal][COLOR=darkgoldenrod]add[/color][teal]([/teal][highlight][b]new[/b] [COLOR=darkgoldenrod]Option[/color][teal]([/teal][/highlight][green][i]"Text"[/i][/green][teal],[/teal] [green][i]"Value"[/i][/green][highlight][teal])[/teal][/highlight][teal]);[/teal]


Feherke.
 
Hi

Grr. Wrong. Missed an important detail :
JavaScript:
window[teal].[/teal]opener[teal].[/teal]document[teal].[/teal]form1[teal].[/teal]InputContainer$LetterInput$lstReasons[highlight][teal].[/teal]options[/highlight][teal].[/teal][COLOR=darkgoldenrod]add[/color][teal]([/teal][b]new[/b] [COLOR=darkgoldenrod]Option[/color][teal]([/teal][green][i]"Text"[/i][/green][teal],[/teal] [green][i]"Value"[/i][/green][teal]));[/teal]
Of course, supposing that by "listbox" you mean a [tt]select[/tt] element.

Feherke.
 
No luck, I get the same "no such interface supported" error.

Thanks though!
 
Hi

Then do it the traditional way :
JavaScript:
[gray]// single line[/gray]
window[teal].[/teal]opener[teal].[/teal]document[teal].[/teal]form1[teal].[/teal]InputContainer$LetterInput$lstReasons[teal].[/teal]options[teal][[/teal]window[teal].[/teal]opener[teal].[/teal]document[teal].[/teal]form1[teal].[/teal]InputContainer$LetterInput$lstReasons[teal].[/teal]options[teal].[/teal]length[teal]]=[/teal][b]new[/b] [COLOR=darkgoldenrod]Option[/color][teal]([/teal][green][i]"Text"[/i][/green][teal],[/teal] [green][i]"Value"[/i][/green][teal])[/teal]

[gray]// or abit more readable in two steps[/gray]

[b]var[/b] sel[teal]=[/teal]window[teal].[/teal]opener[teal].[/teal]document[teal].[/teal]form1[teal].[/teal]InputContainer$LetterInput$lstReasons
sel[teal].[/teal]options[teal][[/teal]sel[teal].[/teal]options[teal].[/teal]length[teal]]=[/teal][b]new[/b] [COLOR=darkgoldenrod]Option[/color][teal]([/teal][green][i]"Text"[/i][/green][teal],[/teal] [green][i]"Value"[/i][/green][teal])[/teal]
Again, supposing that by "listbox" you mean a [tt]select[/tt] element.

And of course also supposing that your reference to the [tt]select[/tt] is correct and allowed.


Feherke.
 
By posting here I've managed to show exactly how much of a noob I really am!

The traditional way is giving me the classic 'Object doesn't support this property or method'. Gotta love MS, they make tools that look so nice but have absolutely no use whatsoever.

I really don't know if my listbox is a 'select' element or not. What I have is a VS2008 project consisting of aspx pages. The listbox I'm using is right out of the standard toolbox.

I'm assuming the reference is correct and allowed, as the textbox in the same input container populates with the code I listed above.

But nonetheless, thanks a million for your effort.
 
Hi

The listbox demo at W3Schools shows that indeed generates a HTML [tt]select[/tt] element.

If you could post some of the HTML code your ASP generates ( as it is displayed by the browser's View source command ), we would have better chances to debug it. Otherwise you will have to wait for someone versed in ASP.


Feherke.
 
Thanks, seems like it *should* work to me. Here's the textbox and listbox rendered code from the parent page:

<td class="style4">Reasons:&#160;&#160;&#160;&#160;&#160; </td>
<td class="style3"><textarea name="InputContainer$LetterInput$txtReasons" rows="2" cols="20" id="InputContainer_LetterInput_txtReasons" style="height:100px;width:380px;"></textarea><br />
<select size="4" name="InputContainer$LetterInput$lstReasons" multiple="multiple" id="InputContainer_LetterInput_lstReasons" style="width:380px;">

</select></td>


And here's the script section from the child:


<script type="text/javascript">

function CloseMe()
{
var txtVal = document.form1.txtReasons.value;
var o = document.createElement("option");
o.text = txtVal;
o.value = "1";
window.opener.document.form1.InputContainer$LetterInput$txtReasons.value = txtVal;
//window.opener.document.form1.InputContainer$LetterInput$lstReasons.items.add(new item("Test Reason", "0"));

var sel=window.opener.document.form1.InputContainer$LetterInput$lstReasons;
sel.options[sel.options.length]=new Option("Test Option", "0");

window.opener = top;
window.close();
}


</script>
 
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...

feherke, thank you for your valuable help -- it did point me in a good direction!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top