If i have an input like so:
<input type="text" id="textvalue" />
the following code will change its value:
$(document).ready(function() {
$('#textvalue').val("hello");
});
however the following will not work:
$(document).ready(function() {
var = "hello";
$('#textvalue').val(var);
});
Why does the second one not work? I need to be able to change the value of the textbox to the value of a variable
Your var
statement needs to look something like this
var something = "hello"
$('#textvalue').val(something );
Right now your not actually assigning a value to a variable, and then you are trying to use the var
keyword.
Variable Reference
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With