assign value to select box ( form validation )
I am creating some form validation, and I have fields working great. The trickyness seems to arise from parsing value from select box
I know how to assign the value within form element, we have:
<select id="sms" name="sms" class="medium">
<optgroup label="SMS Alerts">
<option value="">Please choose</option>
<option value="1">Yes</option>
<option value="0">No</option>
</optgroup>
</select>
But I am not sure what to do within the js for select box.
Currently for a field I have:
$("#mobile").blur(function() {
if(validate_form_field($(this), $(this).val().length>9)) {
mobile_passed = true;
} else {
mobile_passed = false;
}
});
Essentially, I want to validate that value =1 from select box. Do I do something like ?
$("#sms").blur(function() {
if(validate_form_field($(this), $(this).val().length=1)) {
sms_passed = true;
} else {
sms_passed = false;
}
});
Cheers Ste
ADDED Info:
The form is to propagate a progress bar.
So here is a portion of the script, split into 3 main parts within js. I have included field and the select box, to see where I am goin wrong.
var mobile_passed = false;
var sms_passed = false;
$("#mobile").blur(function() {
if(validate_form_field($(this), $(this).val().length>9)) {
mobile_passed = true;
} else {
mobile_passed = false;
}
});
$("#sms").blur(function() {
if(validate_form_field($(this), $(this).val().length=1)) {
sms_passed = true;
} else {
sms_passed = false;
}
});
var $object_mobile = $("#mobile");
no_errors = validate_form_field($object_mobile, $object_mobile.val().length>9);
var $object_sms = $("#sms");
no_errors = valid开发者_如何转开发ate_form_field($object_sms, $object_sms.val().length=1);
Plan B
What if I ditch the select box idea, and add an input field as I know these work. But validate if user types YES
How would I achieve that ??
$("#sms").blur(function() {
if(validate_form_field($('#sms option:selected').val()), $('#sms option:selected').val().length=1)) {
sms_passed = true;
} else {
sms_passed = false;
}
});
精彩评论