/    Sign up×
Community /Pin to ProfileBookmark

dynamic naming of fields and validation with javascript

i have a page that i am creating were there are multiple drop downs, which can change dynamically. Each drop down has and associated set of Radio buttons (2). Each set is given a name such as radaccess and a number (I.E radaccess1, radaccess2, etc…) depending on the number of drop downs, again done dynamically. Now my problem is that when the page loads i am filling the form with values from a DB and trying to set whether the radio button, per specific drop down, is checked or not. the problem is that i can not figure out how to reference these values.

I have tried writing something like document.frmusered.radaccess+i+[0].checked = true;

but these does not work.

i have even tried to build a string like

for(var i = 0; i < (writecnt); i++) –> “writecnt = the number of drop downs”

var radaccess = ‘document.frmusered.radaccess’;

radaccess += i;
radaccess += ‘[0].disabled = true;’;

radaccess;

“even tried document.write(radaccess); but as you have figured out that didnt work out well”

radaccess = ‘document.frmusered.radaccess’;
radaccess += i;
radaccess += ‘[1].disabled = true;’;

radaccess;

i know this cant be that difficult to figure out. Can someone point out what i am over looking.

Thank you.

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@Logic_AliAug 08.2008 — 
I have tried writing something like document.frmusered.radaccess+i+[0].checked = true;

but these does not work.
[/quote]
Without seeing your code I would guess that you need this syntax:document.frmusered['radaccess'+i][0].checked = true;
×

Success!

Help @talind spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...