JScript passing value

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

    JScript passing value

    Hi folks,

    Any ideas why this doesn't work?

    <SCRIPT LANGUAGE="JavaS cript">
    <!--
    f = document.forms[1];
    e = f.elements;
    str = new String(e[0].value);
    len = document.forms['testform'].d.options.leng th;
    document.forms['testform'].d.options[len] = new Option(str, '1');
    </script>

    Basicaly, I am trying to fill my combo box on a HTML page (SELECT OPTION
    field) manually, but the vallue I get every time is 'null', i.e. empty
    string.
    *Suspected error in the red line, since if I put in the last line "....new
    Option('some',' 1');" it works.

    I must have made some ridiculous error I can't see, so plz be free to make
    fun of me :))

    Thanks in advance.
    IS
    btw. if I put up an event at the Text field (onChange) the values can be transfered to my combo box trought a function call, but are lost as soon as I press Submit button I have next to my Text field.


  • kaeli

    #2
    Re: JScript passing value

    In article <bp3d66$6ec$1@s hiva.neobee.net >, finansije@yahoo .com
    enlightened us with...[color=blue]
    > Hi folks,
    >
    > Any ideas why this doesn't work?[/color]

    You only have one form on the page?
    [color=blue]
    >
    > <SCRIPT LANGUAGE="JavaS cript">[/color]

    <script type="text/javascript">
    [color=blue]
    > <!--
    > f = document.forms[1];[/color]

    This gets the second form. I hope that was what you wanted.
    Otherwise, forms[0].
    [color=blue]
    > e = f.elements;
    > str = new String(e[0].value);[/color]
    I hope this element has a value and is either a text input or text area.
    You didn't check.
    [color=blue]
    > len = document.forms['testform'].d.options.leng th;[/color]
    I hope the select is named d.
    [color=blue]
    > document.forms['testform'].d.options[len] = new Option(str, '1');
    > </script>
    >
    > Basicaly, I am trying to fill my combo box on a HTML page (SELECT OPTION
    > field) manually, but the vallue I get every time is 'null', i.e. empty
    > string.
    > *Suspected error in the red line, since if I put in the last line "....new
    > Option('some',' 1');" it works.[/color]

    No "Red lines" for people with plain text mail readers.
    [color=blue]
    >[/color]

    You maybe better off using names, not numbers. Otherwise, if you move
    elements around, you have to change all the code! I suspect the problem
    is with e[0].value.
    Try e["elementnam e"].value

    Oh, and submitting "loses" values - the form blanks out once the page
    location changes.

    --
    --
    ~kaeli~
    In democracy your vote counts. In feudalism your count votes.



    Comment

    Working...