/    Sign up×
Community /Pin to ProfileBookmark

Paring down my code

I have a set of 18 text boxes. Based on a dropdown choice, one half, the other half, all or none of the boxes become disabled. I have a function that does this, but it is ridiculously long. Hoping you can help me make it more efficient. Here is a portion of the function to give you an idea:

[CODE] else if (document.a2.dd2.selectedIndex==1){
document.a2.probe2.checked=true;
document.a2.spouseExp1.disabled=true;
document.a2.spouseExp1.className=”disabled”;
document.a2.spouseExp2.disabled=true;
document.a2.spouseExp2.className=”disabled”;
document.a2.spouseExp3.disabled=true;
document.a2.spouseExp3.className=”disabled”;
document.a2.spouseExp4.disabled=true;
document.a2.spouseExp4.className=”disabled”;
document.a2.spouseExp5.disabled=true;
document.a2.spouseExp5.className=”disabled”;
document.a2.tpExp1.disabled=false;
document.a2.tpExp1.className=””;
document.a2.tpExp2.disabled=false;
document.a2.tpExp2.className=””;
document.a2.tpExp3.disabled=false;
document.a2.tpExp3.className=””;
document.a2.tpExp4.disabled=false;
document.a2.tpExp4.className=””;
document.a2.tpExp5.disabled=false;
document.a2.tpExp5.className=””;
location.href=”#probe3Anchor”
}
[/CODE]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@KorJun 12.2006 — use JSON

document.forms['formname'].elements['elname']

or the JSON variant

document.forms['formname']['elname']

and a loop
<i>
</i>var f = document.forms['a2'];
var i=1;
while(f['spouseExp'+i]){
f['spouseExp'+i].disabled='true';
f['spouseExp'+i].className='disabled';
f['tpExp'+i].disabled='false';
f['tpExp'+i].className='';
i++;
}
Copy linkTweet thisAlerts:
@betheballauthorJun 12.2006 — Thanks Kor, that is much cleaner.
×

Success!

Help @betheball 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.18,
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,
)...