I have a select box with 30 values, one of them is 'selected' by default. What I need to do is if anything but the 'selected' value is selected change a variable to true.
$('.secondNext').click(function(){
var vali_field = $(".udf-selection option:selected").val(),
id = $('.hiddenRuleID').val(),
tranType = [],
ruleStep = 'step2',
tranTypeSel = false,
validFieldSel = false;
$('.checkboxGroup input[type="checkbox"]').each(function() {
if ($(this).is(":checked")) {
tranTypeSel = true;
}
});
if (tranTypeSel == false) {
$('.secondNext').removeClass('next');
$('.tranTypeError').show();
$('.tranTypeError').text('* Please select a transaction type');
alert('Please select at least one checkbox');
return false;
}
if (valiFieldSel == false) {
$('.secondNext').removeClass('next');
$('.udfError').show();
$('.udfError').text('* Please select a UDF');
alert('Please select at least one udf');
return false;
}
$('input[name=tranType]:checked').each(function() {
tranType.push($(this).val());
});
$.ajax({
url: 'ajax/updateNewRule.php',
type: 'POST',
data: {
id: id,
vali_field: vali_field,
tranType: tranType,
ruleStep: ruleStep
}
})
.done(function(data) {
})
})
I have tried the above but it thinks there is something selected because one of the values has the selected attribute.
UPDATE
Heres the scenario in a fiddle - http://jsfiddle.net/csLAk/8337/