Salman Quader Salman Quader - 1 year ago 80
Javascript Question

val() function does not work in html field which is type number

JS

$.ajax({
url: "ajax_call.php",
type:"POST",
data:{dist_task_id:task_id},
success: function(result){
//var rs = result;
alert(result);//working
alert(rs);//working
$(".wtime").val(result);//not working
$(".wtime").val(rs);//not working
}
});


Html

<input class="form-control comm wtime" type="number" step="any" required id="latbox" value="" min="0" max="20" name="w_time[]">


I have html field which type is number. val() function can't set value in that field.
Why???

Answer Source

Ensure "Result" is of type interger, then make sure it's within your min and max properties in your HTML.

$(".wtime").val(parseInt(result))