JS help
- Started
- Last post
- 9 Responses
- ldww
i am using a dropdown with an onClick to trigger this javascript, but its erroring out, can you shed some light on it?
function selectCard() {
if(document.form1.useCard.value = "stored"){
document.form1.cardNum.disabled = true;
document.form1.expMonth.disabled = true;
document.form1.expYear.disabled = true;
} else {
document.form1.cardNum.value = "";
document.form1.cardNum.disabled = flase;
document.form1.expMonth.disabled = false;
document.form1.expYear.disabled = false;
}
}
- ********0
check your brackets
- dc_again0
you've spelt 'false' wrong in the first line of your else statement,
- ldww0
at least now its not erroring... but its not actually doing anything.... if you select new card its supposed to not disable the inputs
- dc_again0
you're in a mess there ldww.
firstly, you're not actually testing anything 'real'. you're testing document.form1.useCard.value, but useCard doesn't have a value as it's a select element. the selected option has a value, but not the select itself. so you need to check that.
secondly, you're not asking if your 'unreal' value is the same as 'stored'. to do that you have to use TWO equal signs. this performs an equality test on the variables/values on eaither side of the equal signs.
try this, it should work...
function selectCard() {
var thevalue = document.form1.useCard.options[d...
if( thevalue== "stored"){
document.form1.NEWcardNum.disabl... = true;
document.form1.NEWexpMonth.disab... = true;
document.form1.NEWexpYear.disabl... = true;
} else {
document.form1.NEWcardNum.value = "";
document.form1.NEWcardNum.disabl... = false;
document.form1.NEWexpMonth.disab... = false;
document.form1.NEWexpYear.disabl... = false;
}
}
- ldww0
thats it! thanks.
i had no idea where to start, i never write js. thanks
- ldww0
one more quick one.... how do i reference a radio button?
the name cardType and the value is visa (or if i could just call all 4 radios in 1 that would be ok too)i tried
document.form1.NEWcardType.disab... = false;
and
document.form1.NEWcardType.visa... = false;
- dc_again0
because a set of radio buttons are an array, you need to reference them as such. so you would disable them like this:
document.form1.NEWcardType[0].di... = false;
document.form1.NEWcardType[1].di... = false;
document.form1.NEWcardType[2].di... = false;
document.form1.NEWcardType[3].di... = false;(remember, it's js so four elements would be 0 to 3, not 1 to 4).
or loop through them:
for(i=0;i
- dc_again0
whoops. as i was saying, loop through them like this:
for(i=0;i
- dc_again0
arrrghhhh
i'll try one last time. loop through them like this:
for(i=0;i[LESS THAN SIGN!!]document.form1.NEWcardTyp...
document.form1.NEWcardType[i].di... = false;
}if it's just one radio button, it's a variable not an array, so disable it in the normal way:
document.form1.NEWcardType.disab... = false;
hope this makes sense.
p.s. forgot to say - don't use a onClick in a select element, use a onChange.