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

About opener.document.forms[0]

P: n/a
Hi,
I've been working with this without problems:

function regresaValor()
{
var indexValor = document.forms[0].eleccion.selectedIndex;
var valueValor =
document.forms[0].eleccion.options[indexValor].value;
opener.document.forms[0].valorTxt.value = valueValor;
window.close();
}

As you can see, this JS function returns 1 value to the parent.
However, I'm trying to return several values to the same parent's
element (valorTxt). Something like this:

function regresaValor()
{
var indexValor0 = document.forms[0].eleccion0.selectedIndex;
var valueValor0 =
document.forms[0].eleccion0.options[indexValor].value;
var indexValor1 = document.forms[0].eleccion1.selectedIndex;
var valueValor1 =
document.forms[0].eleccion1.options[indexValor].value;
var indexValor2 = document.forms[0].eleccion2.selectedIndex;
var valueValor2 =
document.forms[0].eleccion2.options[indexValor].value;
var total = valueValor0 + ";" + valueValor1 + ";" valueValor2;
opener.document.forms[0].valorTxt.value = total;
window.close();
}

This should return a String value to the parent, where I can do
further analysis.

Is this approach the best? Can it be done? Thank you for your time and
advices.

- Omar.
Jul 23 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Omar wrote:
Hi,
I've been working with this without problems:

function regresaValor()
{
var indexValor = document.forms[0].eleccion.selectedIndex;
var valueValor =
document.forms[0].eleccion.options[indexValor].value;
opener.document.forms[0].valorTxt.value = valueValor;
window.close();
}

As you can see, this JS function returns 1 value to the parent.
However, I'm trying to return several values to the same parent's
element (valorTxt). Something like this:

function regresaValor()
{
var indexValor0 = document.forms[0].eleccion0.selectedIndex;
var valueValor0 =
document.forms[0].eleccion0.options[indexValor].value;
var indexValor1 = document.forms[0].eleccion1.selectedIndex;
var valueValor1 =
document.forms[0].eleccion1.options[indexValor].value;
var indexValor2 = document.forms[0].eleccion2.selectedIndex;
var valueValor2 =
document.forms[0].eleccion2.options[indexValor].value;
var total = valueValor0 + ";" + valueValor1 + ";" valueValor2;
opener.document.forms[0].valorTxt.value = total;
window.close();
}

This should return a String value to the parent, where I can do
further analysis.

Is this approach the best? Can it be done? Thank you for your time and advices.

- Omar.


You don't necessarily need to send that to a text input (which is not a
programming construct) to 'analyze' it...depends on what you had in
mind. #;-)

Anyway...

function regresaValor()
{
var els = document.forms[0].elements,
opform, valorTxt, sel, n = 0, els,
data = [];
if (opener
&& !opener.closed
&& (opform = opener.document.forms[0])
&& (valorTxt = opform.elements.valorTxt))
{
while (sel = els['eleccion' + n++])
data.push(sel.value);
valorTxt.value = data.join('; ');
}
window.close();
}

Will process elements named 'eleccion0', 'eleccion1', etc., until there
isn't one. Array.push() adds to the end of the array, .join() pastes
the elements into a string with its argument as seperator. Just one
approach.

Jul 23 '05 #2

P: n/a
ro*****@yahoo.com (Omar) wrote in message news:<8b**************************@posting.google. com>...
Hi,
I've been working with this without problems:

function regresaValor()
{
var indexValor = document.forms[0].eleccion.selectedIndex;
var valueValor =
document.forms[0].eleccion.options[indexValor].value;
opener.document.forms[0].valorTxt.value = valueValor;
window.close();
}

As you can see, this JS function returns 1 value to the parent.
However, I'm trying to return several values to the same parent's
element (valorTxt). Something like this:

function regresaValor() {
var indexValor0 = document.forms[0].eleccion0.selectedIndex;
var valueValor0 =
document.forms[0].eleccion0.options[indexValor].value;
var indexValor1 = document.forms[0].eleccion1.selectedIndex;
var valueValor1 =
document.forms[0].eleccion1.options[indexValor].value;
var indexValor2 = document.forms[0].eleccion2.selectedIndex;
var valueValor2 =
document.forms[0].eleccion2.options[indexValor].value;
var total = valueValor0 + ";" + valueValor1 + ";" valueValor2;
opener.document.forms[0].valorTxt.value = total;
window.close();
}

This should return a String value to the parent, where I can do
further analysis.

Is this approach the best? Can it be done? Thank you for your time and
advices.

- Omar.

i don't know exactly but what value is the function returning ???
try using ',' instead of ';' maybe that will help.
Jul 23 '05 #3

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

function regresaValor()
{
var els = document.forms[0].elements,
opform, valorTxt, sel, n = 0, els,
data = [];


You have declared 'els' twice, but (to my surprise) it doesn't seem
to cause an error. Even something like:

var els = document.forms[0].elements;
var els;

does not seem to be an issue. I guess this highlights that a variable
is not given a value until it is assigned one, so simply initialising
'els' a second time does nothing?
[...]
--
Rob
Jul 23 '05 #4

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

function regresaValor()
{
var els = document.forms[0].elements,
opform, valorTxt, sel, n = 0, els,
data = [];


You have declared 'els' twice, but (to my surprise) it
doesn't seem to cause an error. Even something like:

var els = document.forms[0].elements;
var els;

does not seem to be an issue. I guess this highlights that a
variable is not given a value until it is assigned one, so
simply initialising 'els' a second time does nothing?


It is more surprising to find that:-

var els;
var els = document.forms[0].elements;

- also works, and results in - els - having the assigned value in
subsequent code. But ECMA 262 Section10.1.3 explains why it is not a
problem. But also why there is wasted processing in defining local
variables more than once.

Richard.
Jul 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.