How I extract value from selected arrays

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

    How I extract value from selected arrays

    I am trying to write a simple Javascript code to pass value from a
    listbox to another field

    the following is my code

    f=document.form s[0];
    window.alert(f. FieldList.optio ns.length)
    for(i=0;i<f.Fie ldList.options. length;i++)
    {
    if(f.FieldList. options[i].selected){
    sReturn=f.Field List.options[i].value -------> this line doesn't seem
    to work.
    sReturn+=sRetur n +","
    window.alert(sR eturn)}
    }
    Target=document .forms[0].RefTargetField .value;
    TargetField=eva l("window.opene r.document.form s[0]." +Target);
    TargetField.val ue=sReturn;
    window.close()

    Can help me figure out what I need to do to get the selected value to
    sReturn?

    Thanks
  • kaeli

    #2
    Re: How I extract value from selected arrays

    In article <c9e0fe8b.04051 70647.33e2245e@ posting.google. com>,
    effendi@epitome .com.sg enlightened us with...[color=blue]
    > I am trying to write a simple Javascript code to pass value from a
    > listbox to another field
    >
    > the following is my code
    >
    > f=document.form s[0];
    > window.alert(f. FieldList.optio ns.length)
    > for(i=0;i<f.Fie ldList.options. length;i++)
    > {
    > if(f.FieldList. options[i].selected){
    > sReturn=f.Field List.options[i].value -------> this line doesn't seem
    > to work.
    > sReturn+=sRetur n +","
    > window.alert(sR eturn)}
    > }
    > Target=document .forms[0].RefTargetField .value;
    > TargetField=eva l("window.opene r.document.form s[0]." +Target);
    > TargetField.val ue=sReturn;
    > window.close()
    >
    > Can help me figure out what I need to do to get the selected value to
    > sReturn?
    >[/color]

    I assume this is a select that can be multiple. Because there's no other
    reason to loop through the options to get the selected one.
    Assuming that, you wanted sReturn += f.FieldList.opt ions[i].value and
    you wanted to initialize sReturn to the empty string first. Note that
    with no other code, I can't see if sReturn was declared OUTSIDE the if
    or for block, as it would need to be.

    Now, I see no other code, so I can't tell you why it "isn't working".
    Especially since I don't know what you mean by that. What isn't working?
    What happens? What browser? Did you check for errors? Did you check that
    the form element you're accessing has properly formed HTML with values
    for the options? It is legal, IIRC, to have options with no values.
    Since I have no code here, I can't see if that is the case.

    How about a working example or a link?

    The best I can do with no other code:

    var sReturn=""; // needed here or it is local to the for block and
    unavailable when referenced for TargetField.val ue
    f=document.form s[0];
    window.alert(f. FieldList.optio ns.length)
    for(i=0;i<f.Fie ldList.options. length;i++)
    {
    if(f.FieldList. options[i].selected)
    {
    sReturn+=f.Fiel dList.options[i].value;
    sReturn+=sRetur n +",";
    window.alert(sR eturn);
    }
    }
    Target=document .forms[0].RefTargetField .value;
    TargetField=eva l("window.opene r.document.form s[0]." +Target);
    TargetField.val ue=sReturn;
    window.close()

    --
    --
    ~kaeli~
    To steal ideas from one person is plagiarism; to steal from
    many is research.



    Comment

    • bruce

      #3
      Re: How I extract value from selected arrays

      effendi@epitome .com.sg (Fendi Baba) wrote in message news:<c9e0fe8b. 0405170647.33e2 245e@posting.go ogle.com>...[color=blue]
      > I am trying to write a simple Javascript code to pass value from a
      > listbox to another field
      >
      > the following is my code
      >
      > f=document.form s[0];
      > window.alert(f. FieldList.optio ns.length)
      > for(i=0;i<f.Fie ldList.options. length;i++)
      > {
      > if(f.FieldList. options[i].selected){
      > sReturn=f.Field List.options[i].value -------> this line doesn't seem
      > to work.
      > sReturn+=sRetur n +","
      > window.alert(sR eturn)}
      > }
      > Target=document .forms[0].RefTargetField .value;
      > TargetField=eva l("window.opene r.document.form s[0]." +Target);
      > TargetField.val ue=sReturn;
      > window.close()
      >
      > Can help me figure out what I need to do to get the selected value to
      > sReturn?
      >
      > Thanks[/color]


      That line that you question, works for me. Perhaps there's an error
      in your HTML for the select box.

      Comment

      • Fendi Baba

        #4
        Re: How I extract value from selected arrays

        bruce_brodinsky @glic.com (bruce) wrote in message news:<d3654513. 0405171148.68e6 5043@posting.go ogle.com>...[color=blue]
        > effendi@epitome .com.sg (Fendi Baba) wrote in message news:<c9e0fe8b. 0405170647.33e2 245e@posting.go ogle.com>...[color=green]
        > > I am trying to write a simple Javascript code to pass value from a
        > > listbox to another field
        > >
        > > the following is my code
        > >
        > > f=document.form s[0];
        > > window.alert(f. FieldList.optio ns.length)
        > > for(i=0;i<f.Fie ldList.options. length;i++)
        > > {
        > > if(f.FieldList. options[i].selected){
        > > sReturn=f.Field List.options[i].value -------> this line doesn't seem
        > > to work.
        > > sReturn+=sRetur n +","
        > > window.alert(sR eturn)}
        > > }
        > > Target=document .forms[0].RefTargetField .value;
        > > TargetField=eva l("window.opene r.document.form s[0]." +Target);
        > > TargetField.val ue=sReturn;
        > > window.close()
        > >
        > > Can help me figure out what I need to do to get the selected value to
        > > sReturn?
        > >
        > > Thanks[/color]
        >
        >
        > That line that you question, works for me. Perhaps there's an error
        > in your HTML for the select box.[/color]


        Thanks. As it turn out the field had an error. Thanks for the response

        Comment

        Working...