jQuery change input text value
no, you need to do something like:
$('input.sitebg').val('000000');
but you should really be using unique IDs if you can.
You can also get more specific, such as:
$('input[type=text].sitebg').val('000000');
EDIT:
do this to find your input based on the name attribute:
$('input[name=sitebg]').val('000000');
Jquery Setting Value of Input Field
This should work.
$(".formData").val("valuesgoeshere")
For empty
$(".formData").val("")
If this does not work, you should post a jsFiddle.
Demo:
$(function() { $(".resetInput").on("click", function() { $(".formData").val(""); });})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><input type="text" class="formData" value="yoyoyo">
<button class="resetInput">Click Here to reset</button>
How to set value of an input field using jQuery
Simply Edit the script: change html
to val
<script>
setInterval(function() {
var local = new Date();
var localdatetime = local.getHours() + ":" + pad(local.getMinutes()) + ":" +
pad(local.getSeconds());
$('#local-time').val(localdatetime);
}, 1000);
function pad(t) {
var st = "" + t;
while (st.length < 2)
st = "0" + st;
return st;
}
</script>
Set value of input text field inside jquery.on
You gave wrong id in selector txt_feeamount
should be fee_amount
as the input you have has id fee_amount
not txt_feeamount
Note you can get the source of event using $(this)
or this
instead of var btn = $(":input[type=button]:focus");
Here :focus does not make any sense as well.
Live Demo
$('input.btne').on('click', function () {
$("#fee_amount").val($(this).attr('amount'));
});
Defining attribute like you have amount is not good practice. You should use data-* attributes. The amount attribute will be data-amount.
Using data- to define data attributes
Live Demo
Html
<input type="text" id="fee_amount" />
<input type="button" id="idF" class="btne" optionText="My option Text" data-amount="123.00" value="Edit" />
Javascript
$('input.btne').on('click', function () {
$("#fee_amount").val($(this).data('amount'));
});
how to set a value to an input field onclick with jquery
You can use:
const hidden_value = $('input[type="hidden"]').val();
to get the value from the hidden
input and then set it's value on the input with the id
john using:
$("#john").val(hidden_value)
See working example below:
$("span").click(function(){ const hidden_value = $('input[type="hidden"]').val(); // get the value from the hidden input $("#john").val(hidden_value); // set the element with the id john to have the retrieved value});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><p>Name: <input id="john" type="text" value="" name="user"></p><input type="hidden" value="John" /><span>Set value</span>
Detecting value change of input[type=text] in jQuery
Update - 2021
As of 2021 you can use input
event for all the events catering input value changes.
$("#myTextBox").on("input", function() {
alert($(this).val());
});
Original Answer
just remember that 'on' is recommended over the 'bind' function, so always try to use a event listener like this:
$("#myTextBox").on("change paste keyup", function() {
alert($(this).val());
});
Related Topics
Difference Between Client-Side and Server-side Programming
Download File Using an Ajax Request
How to Call PHP Functions by JavaScript
Execute PHP Function With Onclick
JavaScript Does Not Fire After Appending
"Mixed Content Blocked" When Running an Http Ajax Operation in an Https Page
Pass JavaScript Variable to PHP Via Ajax
Encrypt With PHP, Decrypt With JavaScript (Cryptojs)
How to Refresh Page on Back Button Click
Determine Timezone from Latitude/Longitude Without Using Web Services Like Geonames.Org
Displaying Pdf from Arraybuffer
Jquery Load() Only Working in Firefox
Changing CSS Values With JavaScript
How to Change Div Content With JavaScript
How to Autosize a Textarea Using Prototype
How to Get the Pure Text Without HTML Element Using JavaScript