Problems between children and parents windows

O

Omar

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,status=no,toolbar=no,width=350,height=200,menubar=no,directories=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.
 
R

RobB

Omar said:
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' said:
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.
 
R

RobG

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','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.

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top