By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,769 Members | 1,237 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,769 IT Pros & Developers. It's quick & easy.

Problems between children and parents windows

P: n/a
Hi,

I'm trying to pass values from a parent window to a child. The value
I'm interested is the user selected option of a SELECT element, as
follows:

<input type='button' value='Asigna valor' name='valor' align='left'
onClick=window.open('valor.jsp?variable=documents. forms[0].variable.options[document.forms[0].variable.selectedIndex].value','child','resizable=yes,scrollbars=yes,stat us=no,toolbar=no,width=350,height=200,menubar=no,d irectories=no,dependent=yes,hotkeys=1,alwaysRaised =1');></td>

I think the mistake is in the way I'm passing the value:

valor.jsp?variable=documents.forms[0].variable.options[document.forms[0].variable.selectedIndex].value

Could you, please, help me to figure it out?

TIA.
Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Omar wrote:
Hi,

I'm trying to pass values from a parent window to a child. The value
I'm interested is the user selected option of a SELECT element, as
follows:

<input type='button' value='Asigna valor' name='valor' align='left'
onClick=window.open('valor.jsp?variable=documents. forms[0].variable.options[document.forms[0].variable.selectedIndex].value','child','resizable=yes,scrollbars=yes,stat us=no,toolbar=no,width=350,height=200,menubar=no,d irectories=no,dependent=yes,hotkeys=1,alwaysRaised =1');></td>
I think the mistake is in the way I'm passing the value:

valor.jsp?variable=documents.forms[0].variable.options[document.forms[0].variable.selectedIndex].value
Could you, please, help me to figure it out?

TIA.


The url is a string - but the querystring parameter needs to be
extracted, and that takes JavaScript code, not a string. You could just
remove the code from the quotes, but, might as well un-clutter
things...

<input type="button" value="Asigna valor" name="valor" align="left"
onclick="var
s=documents.forms[0].variable,v=s.options[s.selectedIndex].value;window.open('valor.jsp?variable='+v,'child' ,'resizable=yes........

Might be better to move the whole thing into a global function.
Presumably you're extracting this data from window.location.search in
the pop-up. Can also pass data directly, programmatically, between
window objects.

Jul 23 '05 #2

P: n/a
RobB wrote:
[...]

The url is a string - but the querystring parameter needs to be
extracted, and that takes JavaScript code, not a string. You could just
remove the code from the quotes, but, might as well un-clutter
things...

<input type="button" value="Asigna valor" name="valor" align="left"
onclick="
var v = documents.forms[0].variable,
s = documents.forms[0].variable,v=s.options[s.selectedIndex].value;
Remind me why we do this. Seems that the value of a select is the
value of the selected option, or if not present, the text - unless
it's a multiple select, in which case other methods are required or
the option has a value but the text is required.

All the browsers I tested work as above, so why not:

var v = documents.forms[0].variable.value,
window.open('valor.jsp?variable=' + v,'...'

or

window.open('valor.jsp?variable='+documents.forms[0].variable.value,
'child',
'resizable=yes........

and depending on the value extracted from the form element, it may
also require escaping:

var v = encodeURI(documents.forms[0].variable.value)

Or perhaps the 'selectedIndex' stuff is required to support older
browsers?
window.open('valor.jsp?variable='+v,'child','resiz able=yes........

Might be better to move the whole thing into a global function.
Presumably you're extracting this data from window.location.search in
the pop-up. Can also pass data directly, programmatically, between
window objects.


Wow, no lecture on the evils of pop-ups! ;-)

--
Rob
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.