Forum Moderators: open

Message Too Old, No Replies

Javascript variable assignment problem

         

brynt72

6:48 am on Jul 12, 2003 (gmt 0)

10+ Year Member



Hello All..

This assignment of var1 works no problem.
function test(){
var1=form.input.value
parent.frame.document.form.input_1.value="test"+var1
}
}

I would like to use var1 on the left side of the equation but can't seem to make it happen.

parent.frame.document.form.input_(var1).value="test"

What is the correct syntax for this to work. needs to affect input_(1...2..3..etc..)based on whatever value var1 is.

Please help!
Bryn

ShawnR

2:11 pm on Jul 12, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Bryn & Welcome to WebmasterWorld!

Try something like:

var form_entity = "input_" + var1;
parent.frame.document.form[form_entity].value = ...;

(Note: don't forget to terminate your javascript instructions with semicolons, and declare your variables. Many browsers are pretty tolerant, but you could get caught out if you get lazy ;)

Shawn

PS That should work if the code in your 1st post worked:
parent.frame.document.form.input_1.value="test"+var1
However, something makes me uncomfortable about that code... I'm a bit surprised it works... So what is the name of the form and what is the structure of the html defining the form?