470,594 Members | 1,499 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,594 developers. It's quick & easy.

using variables in a document.form.value string

LRW
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.length; i++)
{
if (document.form1.itemtoedit[i].checked)
{
var rad_val = document.form1.itemtoedit[i].value;
var iq = document.form1.rad_val+'-itemqty'.value;
}
}
itemeditrow.style.visibility = 'visible';
itemeditrow2.style.visibility = 'visible';
document.form1.itemeditnum.value = 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=\"itemtoedit\" type=\"radio\" value=\"".$itemnum."\"
onClick=\"makeItemEditVis();\">item #: ".$itemnum." qty: <input
name=\"".$itemnum."-itemqty\" type=\"text\" size=\"10\"
value=\"".$itemqty."\">
Jul 23 '05 #1
1 16418
Lee
LRW said:
var iq = document.form1.rad_val+'-itemqty'.value;


Access it through the elements array:

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

Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by ratnakarp | last post: by
6 posts views Thread by =?Utf-8?B?U2hhd24gU2VzbmE=?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.