/    Sign up×
Community /Pin to ProfileBookmark

changing class of a form element

Hi

Can I use JS to change the CSS class of a form element?

I have a number of form elements which are enabled or disabled depending on the value of a checkbox, and I’d like to change their class dependent on this too. Here’s what I’ve got at the moment:

function Forward()
{
var ckb1 = document.forms[0].FwdInvoice;
if (ckb1.checked) { document.forms[0].FwdInvAddress.disabled = false
document.forms[0].FwdInvAddress1.disabled = false
document.forms[0].FwdInvAddress2.disabled = false
document.forms[0].FwdInvAddress3.disabled = false
document.forms[0].FwdInvAddress4.disabled = false
document.forms[0].FwdInvAddress5.disabled = false
document.forms[0].FwdInvAddress6.disabled = false
document.forms[0].FwdInvAddress7.disabled = false;
document.forms[0].FwdInvAddress.focus()

} else { document.fees.FwdInvAddress.disabled = true
document.fees.FwdInvAddress1.disabled = true
document.fees.FwdInvAddress2.disabled = true
document.fees.FwdInvAddress3.disabled = true
document.fees.FwdInvAddress4.disabled = true
document.fees.FwdInvAddress5.disabled = true
document.fees.FwdInvAddress6.disabled = true
document.fees.FwdInvAddress7.disabled = true;

}

}

any ideas?

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@Mr_JJul 10.2003 — After setting up your class rules


function Forward()

{

var ckb1 = document.forms[0].FwdInvoice;

if (ckb1.checked) {

[B]document.forms[0].className=myrule1[/B]

document.forms[0].FwdInvAddress.disabled = false
×

Success!

Help @idiotbear 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 5.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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...