Below is my HTML code:
I want the script to run when an option is selected. I think the code I have written in correct. console.log() is not printing anything on the console so this means the function is not invoked. Can anybody help me? This is very basic code but I don't know whats wrong in it.
<div class="form-group required">
<label for="InputLastName">For how many hours ? <sup>*</sup> </label>
<select name="serviceHours" id="hours" onchange="getHours(this.value)">
<option value="" selected>---------</option>
<option value="1">1 Hour</option>
<option value="2">2 Hours</option>
<option value="3">3 Hours</option>
<option value="4">4 Hours</option>
<option value="5">5 Hours</option>
<option value="6">6 Hours</option>
<option value="7">7 Hours</option>
<option value="8">8 Hours</option>
<option value="9">9 Hours</option>
<option value="10">10 Hours</option>
<option value="11">11 Hours</option>
<option value="12">12 Hours</option>
</select>
<script type="text/javascript">
function getHours(value){
var hours = value;
console.log(hours+ " hello");
}
</script>
</div>
If I change the function name the console is not giving an error undefined functions or function not found .
if I replace onchange="getHours(this.value)" with onchange="alert(this.value);" it is not working then also.
Can anyone tell the jquery way of doing this ??