I have a HTML form in which the user enters the amout of time he/she intends to spend on several tasks:
<form>
<div class='row radio-online'>
<div class='col-xs-2'>
<input type='radio' name='time' id='minutes' value='minutes' />Minutes
</div>
<div class='col-xs-2'>
<input type='radio' name='time' id='hours' value='hours' />Hours
</div>
</div>
<div>
<div><input type='text' name='time_task1' id='time_task1' value='' /></div>
<div><input type='text' name='time_task2' id='time_task2' value='' /></div>
<div><input type='text' name='time_task3' id='time_task3' value='' /></div>
</form>
What I want is to convert the values entered to minutes or hours, depending on the option selected on the radio group 'time'. I tried this in jQuery:
$("input[name='time']:radio").change(function() {
if($("input:checked[name='time']:radio").val() == 'minutes') {
// this attempts to get every input that has an id starting with time_task
$("[id^='time_task']").val($("[id^=time_task]").val() * 60);
}
else {
$("[id^='mins']").val($("[id^=mins]").val() / 60);
}
});
The problem is when I tried that, it does make the conversion, but only the value of the first input is converted and in addition, its value is copied to all other inputs, but the correct would be each value will have its value converted individually. The examples I've found do just that, but it's not my case. Any suggestions?