About opener.document.forms[0]

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Omar

    #1

    About opener.document.forms[0]

    Hi,
    I've been working with this without problems:

    function regresaValor()
    {
    var indexValor = document.forms[0].eleccion.selec tedIndex;
    var valueValor =
    document.forms[0].eleccion.optio ns[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.sele ctedIndex;
    var valueValor0 =
    document.forms[0].eleccion0.opti ons[indexValor].value;
    var indexValor1 = document.forms[0].eleccion1.sele ctedIndex;
    var valueValor1 =
    document.forms[0].eleccion1.opti ons[indexValor].value;
    var indexValor2 = document.forms[0].eleccion2.sele ctedIndex;
    var valueValor2 =
    document.forms[0].eleccion2.opti ons[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

    #2
    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.selec tedIndex;
    > var valueValor =
    > document.forms[0].eleccion.optio ns[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.sele ctedIndex;
    > var valueValor0 =
    > document.forms[0].eleccion0.opti ons[indexValor].value;
    > var indexValor1 = document.forms[0].eleccion1.sele ctedIndex;
    > var valueValor1 =
    > document.forms[0].eleccion1.opti ons[indexValor].value;
    > var indexValor2 = document.forms[0].eleccion2.sele ctedIndex;
    > var valueValor2 =
    > document.forms[0].eleccion2.opti ons[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.v alue);
    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.

    Comment

    • sancha

      #3
      Re: About opener.document .forms[0]

      ro_omar@yahoo.c om (Omar) wrote in message news:<8b974ca4. 0504051430.401f 5562@posting.go ogle.com>...[color=blue]
      > Hi,
      > I've been working with this without problems:
      >
      > function regresaValor()
      > {
      > var indexValor = document.forms[0].eleccion.selec tedIndex;
      > var valueValor =
      > document.forms[0].eleccion.optio ns[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.sele ctedIndex;
      > var valueValor0 =
      > document.forms[0].eleccion0.opti ons[indexValor].value;
      > var indexValor1 = document.forms[0].eleccion1.sele ctedIndex;
      > var valueValor1 =
      > document.forms[0].eleccion1.opti ons[indexValor].value;
      > var indexValor2 = document.forms[0].eleccion2.sele ctedIndex;
      > var valueValor2 =
      > document.forms[0].eleccion2.opti ons[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.

      Comment

      • RobG

        #4
        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

        Comment

        • Richard Cornford

          #5
          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.


          Comment

          Working...