using variables in a document.form.value string

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

    #1

    using variables in a document.form.value string

    Below is some of the code I'm using.
    I have a PHP page generating a list of items. I've made it so that
    each one has a radiobutton with a unique value. You can click on the
    radiobutton and it will change the value of a text field to the value
    of the radiobutton--all that works fine!

    Now, I need to also have it populate a textfield with the value of a
    textfield in the row that's selected.
    I can make unique field names, no problem. I think my problem is
    getting the javascript written so that it recognizes the variable.

    Well, see below. As it's written below, the textfield "itemqty" always
    has the value "NaN" (wherever THAT comes from) no matter which
    radiobutton I select.
    I think it's a simple matter of how to concatinate set syntax with a
    variable that's a problem, and if someone can just point me to maybe a
    Webpage that explains it, I'd appreciate it. I haven't been able to
    find anything yet.

    Thanks!
    Liam

    function makeItemEditVis ()
    {
    for (var i=0; i < document.form1. itemtoedit.leng th; i++)
    {
    if (document.form1 .itemtoedit[i].checked)
    {
    var rad_val = document.form1. itemtoedit[i].value;
    var iq = document.form1. rad_val+'-itemqty'.value;
    }
    }
    itemeditrow.sty le.visibility = 'visible';
    itemeditrow2.st yle.visibility = 'visible';
    document.form1. itemeditnum.val ue = rad_val;
    document.form1. itemqty.value = iq;
    }


    And here's part of the form with the radio button and the textfield
    it's getting the values from, supposedly:

    <input name=\"itemtoed it\" type=\"radio\" value=\"".$item num."\"
    onClick=\"makeI temEditVis();\" >item #: ".$itemnum. " qty: <input
    name=\"".$itemn um."-itemqty\" type=\"text\" size=\"10\"
    value=\"".$item qty."\">
  • Lee

    #2
    Re: using variables in a document.form.v alue string

    LRW said:
    [color=blue]
    > var iq = document.form1. rad_val+'-itemqty'.value;[/color]

    Access it through the elements array:

    var iq = document.form1. elements[rad_val+'-itemqty'].value;

    Comment

    Working...