homepage Welcome to WebmasterWorld Guest from 54.167.177.180
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Getting value of input variable based on value passed into function
Jeremy_H

5+ Year Member



 
Msg#: 3241349 posted 11:55 pm on Feb 2, 2007 (gmt 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;}

 

mehh

5+ Year Member



 
Msg#: 3241349 posted 11:07 am on Feb 3, 2007 (gmt 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">

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved