I have the following code with three options in a select box which should dynamically enable/disable the attribute "disable" in the input fields/ textarea / select, but the code doesn't work at all:
$(document).ready(function() {
$('.fieldcontent').not('.info').hide();
$('#selector_cs').change(function() {
$('.fieldcontent').customFadeOut(100);
$('.' + $(this).val()).customFadeIn(900);
// $('input').prop('disabled',false);
//$('textarea').prop('disabled',false);
//$('select').prop('disabled',false);
//option1
if ($("this:selected").val() === 'help') {
$("textarea[name='message']").prop('disabled',false);
$("input[name='domain']").prop('disabled',false);
}else{
$("textarea[name='message']").prop('disabled',true);
$("input[name='domain']").prop('disabled',true);
};
//option2
if ($("this:selected").val() === 'info') {
$("textarea[name='message']").prop('disabled',false);
}else{
$("textarea[name='message']").prop('disabled',true);
};
//option3
if ($("this:selected").val() === 'products') {
$("textarea[name='message']").prop('disabled',true);
$("select[name='products']").prop('disabled',false);
$("input[name='domain']").prop('disabled',false);
$("input[name='address']").prop('disabled',false);
$("input[name='state']").prop('disabled',false);
$("input[name='city']").prop('disabled',false);
$("input[name='country']").prop('disabled',false);
};
}); });
Can anyone help me to write the code properly?
Thanks in advance for any help
EDIT: Thanks @Ken and @arun for the quick help. Now the jQuery is working.
But: I have a PHP validation which doesn't pass with the fiedls disabled by jQuery. Why?
Otherwise, i don't want to add/ remove dynamic hidden fields by jquery, because when the user receive a mail, he would see the hidden fields values, which aren't "real" values, but with values like "some1", "some2" ecc.
How to avoid this and using diasabled fields instead passing the php validation?