I am trying to multiply every Input
value inside Form by 7
to make it a weekly
data and 30
to make it monthly data on select
from drop down.
My form is very big so I can’t do it one by one.
<select name="result_time" class="custom-select type" id="result_time" onChange=selectChange(this.value)>
<option class="daily" value="Daily" selected="selected">Daily</option>
<option class="weekly" value="Weekly">Weekly</option>
<option class="monthly" value="Monthly">Monthly</option>
</select>
<form>
<input type="text" class="form-control" readonly/>
<input type="text" class="form-control" readonly/>
<input type="text" class="form-control" readonly/>
<input type="text" class="form-control" readonly/>
........
</form>
I tried this:
<script>
function selectChange(val) {
if(val == 'Weekly'){
/* multiply every input by 7 */
$('input').val(parseInt('input').val() * 7)
/* I know it's not right but it turns all my input to same value */
}
}
</script>
Also I don’t want to multiply 7 every time user select weekly. How can achieve it in Form?
You can use
each
loop to iterate through inputs and only get value from particular inputs and make changes there.Demo Code :