By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,341 Members | 1,553 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,341 IT Pros & Developers. It's quick & easy.

using variables in a document.form.value string

P: n/a
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.


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;
} = 'visible'; = '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\"
Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply

P: n/a
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.