Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

Getting value of input variable based on value passed into function

11:55 pm on Feb 2, 2007 (gmt 0)

Preferred Member

10+ Year Member

joined:Aug 12, 2005
votes: 0

I have a function that looks similiar to this:

function test(n){var a=document.forms["n"].r2.value;}

The problem is, there's a variable I would like to change called "r2". I would like this to be rn, based on the number pased:

function test(1){var a=document.forms["n"].r1.value;}
function test(2){var a=document.forms["n"].r2.value;}
function test(3){var a=document.forms["n"].r3.value;}

I've tried the following, but it doesn't seem to work. Any ideas? Thanks.

function test(n){var a=document.forms["n"].rn.value;}
function test(n){var a=document.forms["n"].r+n.value;}
function test(n){var a=document.forms["n"].r+n+.value;}
function test(n){var a=document.forms["n"].r+"n"+.value;}
function test(n){var a=document.forms["n"].r"+n+".value;}

11:07 am on Feb 3, 2007 (gmt 0)

Full Member

10+ Year Member

joined:Feb 12, 2006
votes: 0

function getFormInput(inputName,formName)
return document.getElementById(inputName);
else if(document.forms[formName])
return document.forms[formName][inputName];
return false;

the input needs to have the same id as name to work eg
<input type="text" name="hiho">
would become
<input type="text" name="hiho" id="hiho">