Connecting Tech Pros Worldwide Help | Site Map

About opener.document.forms[0]

Omar
Guest
 
Posts: n/a
#1: Jul 23 '05
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.
RobB
Guest
 
Posts: n/a
#2: Jul 23 '05

re: About opener.document.forms[0]


Omar wrote:[color=blue]
> 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[/color]
and[color=blue]
> advices.
>
> - Omar.[/color]

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.

sancha
Guest
 
Posts: n/a
#3: Jul 23 '05

re: About opener.document.forms[0]


ro_omar@yahoo.com (Omar) wrote in message news:<8b974ca4.0504051430.401f5562@posting.google. com>...[color=blue]
> 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()[/color]
[color=blue]
> {
> 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.[/color]


i don't know exactly but what value is the function returning ???
try using ',' instead of ';' maybe that will help.
RobG
Guest
 
Posts: n/a
#4: Jul 23 '05

re: About opener.document.forms[0]


RobB wrote:
[...][color=blue]
> Anyway...
>
> function regresaValor()
> {
> var els = document.forms[0].elements,
> opform, valorTxt, sel, n = 0, els,
> data = [];[/color]

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
Richard Cornford
Guest
 
Posts: n/a
#5: Jul 23 '05

re: About opener.document.forms[0]


RobG wrote:[color=blue]
> RobB wrote:
> [...][color=green]
>> Anyway...
>>
>> function regresaValor()
>> {
>> var els = document.forms[0].elements,
>> opform, valorTxt, sel, n = 0, els,
>> data = [];[/color]
>
> 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?[/color]

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.


Closed Thread


Similar JavaScript / Ajax / DHTML bytes