How to Set value in input field?
To Set the value of the input field, We need to use JQuery val() Method.
$("button").click(function(){
$("input:text").val("Bangla Tutorials Point");
});
The val() method sets the value for the selected elements.
This val() method sets the value of the value for all matched elements.
Mostly Used:
The val() method is mostly used with HTML
Different Syntax of val() Method:
val() Method for return the value:
$(selector).val();
$(selector).val(value);
$(selector).val(function(index,currentvalue));
Here, Value is required. It specifies the of the value attribute
and function(index,currentvalue) is optional. It declear a function that returns a set of value.
Full Project Source Code:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Title of the document</title>
</head>
<body>
<input type="text" name="total" class="form-control" placeholder="Total" id="total">
<br>
<input type="text" name="subtotal" class="form-control" id="subtotal" readonly>
</body>
</html>
//Script should be like this
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#total').change(function() {
var dInput = this.value;
$('#subtotal').val(dInput);
});
});
</script>
Thank you for visiting our blog-site. For more videos please visit our Cahnnel https://www.youtube.com/channel/UCW_xg9-8FU8SINc-EjDQ53g
EmoticonEmoticon