Welcome to WebmasterWorld Guest from 54.166.245.10

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
posts:411
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
posts:224
votes: 0



function getFormInput(inputName,formName)
{
if(document.getElementById)
{
return document.getElementById(inputName);
}
else if(document.forms[formName])
{
return document.forms[formName][inputName];
}
else
{
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">
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members