I'm trying to implement a javascript code for the html5 form that will responsible for disabling/enabling the button until the select element is not selected. Here is the codes:
HTML:
<form name="courseForm" id="courseForm">
<select name="coursetype" id="coursetype" onchange="enableStartBtn()">
<option value="0" selected="selected">Select here...</option>
<option value="1">CourseName 1</option>
<option value="2">CourseName 2</option>
<option value="3">CourseName 3</option>
</select>
<button type="button" id="startBtn" disabled="disabled" onclick="Test()">Start</button>
</form>
and JavaScript:
function enableStartBtn() {
$('#startBtn').removeAttr('disabled');
}
function Test() {
var form = $('#courseForm');
var course = $('#coursetype', form).val();
if (course == '0') {
alert('Select the course first!');
} else if (course == '1') {
alert('CourseName 1 is selected!');
} else if (course == '2') {
alert('CourseName 2 is selected!');
} else if (course == '3') {
alert('This course is not implemented yet');
}
}
I'm using JQuery 1.9.1 in my code, everything looks like ok, but the when value is selected the button is not enables. Any help would be appreciated.
UPDATE: Sorry guys forgot to mention that I'm also using JQuery Mobile 1.3.0, so without including jquery mobile it works, but with jquery mobile not. Here is the jsfiddle version: http://jsfiddle.net/dozent/UVQ4m/
.prop('disabled',false)to enablepropfor this<option value="0" selected="selected" disabled>data-*attribute to target not implemented courses, instead of storing that in the JSupdatepart of my question.