I have got a form with two inputs (there is a PHP script behind it):
<select id="select1">
<option>One</option>
<option>Two</option>
</select>
<input type="text" id="text1" disabled="disabled" />
The PHP script look into a database and mark "One" or "Two" with the selected="selected"
attribute.
If "One" is selected, I want to activate the disabled text field. If any other entry is selected (in this example "Two"), the text field should be disabled. I wrote this jQuery code:
<script type = "text/javascript">
$("#select1").bind('change paste keyup', function() {
if (this.value == 'One') {
$("#text1").prop('disabled', false);
} else {
$("#text1").prop('disabled', true);
}
});
</script>
My Problem: When I visit the page and "One" is preselected, the text field is disabled. I must select "Two" and "One" again. After this, the text field is enabled. I want to check on page load which item is selected. I tried a lot with triggering a change like this, but it did not run:
$(window).bind("load", function() {
$("#select1").trigger('change paste keyup');
});
I know I could use thinks like .on
or .change
, but I want to do it with .bind
.
How can I call .bind
on page load?