I have a form where there's an option group with the choice of entering a value in pounds or a percentage.
Following this I have an input box for the actual value or the percentage.
I want to use the validate functions in jquery to set a conditional maximum value (e.g.100) if the use开发者_开发百科r chooses the percent option.
Is this possible - I tried this but it doesn't work:
sponsorValue: {
required: true,
digits: true,
max: function(element) {
if ($("#sponsorOption").val() == '2'){ return 100;}
}
}
can anyone offer any help?
I think I may have cracked it:
sponsorValue: {
required: true,
digits: true,
max: function(value,element) {
if ($("input[name='sponsorOption']:checked").val() == '2') return 100;
}
}
I used a single checkbox instead of the radios in the end but I may try and retest using the radios.
This is how the html form radios are marked up:
<input name="sponsorOption" type="radio" value="1" /> <span class="stdTxt">Amount</span><br />
<input checked="checked" name="sponsorOption" type="radio" value="2" checked="checked"/> <span class="stdTxt">Percentage</span>
apologies for adding this as an answer my user wasn't set up yesterday.
精彩评论