Reputation: 6330
Hi I have an optins select "Other" which if user clicks on that the Hidden input box will show up and prompts user to validate the input at this DEMO
as:
$('#selType').change(function(){
if($(this).val() == '2') {$('#benOt').show(); }//end of If
else{$('#benOt').css("display", "none");}
});
and I do validation as:
if ($('#selType').val() === "2") {
if ($('#other').val() === "") {
$('#other').parent().after('<div class="alert alert-danger err"> <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>This is a Required Field</div>');
proceed = false;
} else if (!nameRegexnumber.test($('#other').val())) {
$('#other').parent().after('<div class="alert alert-danger err"> <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>Data Type Cant Be Number</div>');
proceed = false;
} else if (!nameRegexshort.test($('#other').val())) {
$('#other').parent().after('<div class="alert alert-danger err"> <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>Data Type Cant Be Short</div>');
proceed = false;
} else {
}
}
So far things works fine BUT I need to get the value for Type so if I chose the other how can I get the value from the input box? what I have done was :
if (proceed) {
file_type = $('#selType').val();
$('#stype').html(file_type);
}
Which make Type = 2 syntactically correct but logically wrong! Can you please let me know how I can fix this?
Upvotes: 0
Views: 70