How do I properly disable and enable form elements using jquery. I need to disable the text form element when I click on the select. And vise versa.
<html>
<head>
<script src="jq.js"></script>
<script>
$(function(){
$('#fromdate').click(function(){
$('#yosh').attr('disabled','disabled');
$('#fromdate').removeAttr('disabled');
});
$('#yosh').click(function(){
$('#yosh').removeAttr('disabled');
$('#fromdate').attr('disabled','disabled');
});
});
</script>
</head>
<body>
Sort by:
<select name="yosh" id="yosh">
<option value="daily">daily</option>
<option value="weekly">yesterday</option>
<option value="weekly">weekly</option>
<option value="monthly">monthly</option>
<option value="yearly">yearly</option>
</select><br/>
date range:<br/>
From:<input type="text" value="" name="fromdate" id="fromdate"></input><br/>
To:<input type="text" value="" name="todate" id="todate"></input><br/>
Customer:<input type="text" value="" name="customer" id="customer"></input>
</body>
</html>
Example of what i've written in the comment:
<span id="spnSel">
<select name="yosh" id="yosh">
<option value="daily">daily</option>
<option value="weekly">yesterday</option>
<option value="weekly">weekly</option>
<option value="monthly">monthly</option>
<option value="yearly">yearly</option>
</select>
</span>
Add this event:
$('#spnSel').mouseover(function () {
$('#yosh').prop('disabled', false);
});
You can do this for the text boxes as well. This may not be the best solution/approach but it will do the job.
the syntax is
$('formelement').attr('disabled',true);
or to re-enable
$('formelement').removeAttr('disabled');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With