I am trying to pass a value from a button to an input value using Javascript. What I mean right now is
inside javascript file
var test2 = 5;
appendeddatahtml = '<div class="test1"><button id="btn" type="button" value="' + test2 + '">This is it!</button></div>';
$("#test1").append(appendeddatahtml);
And this is the form above script
<input type="text" name="latlon" id="latlon" style="display: none; " value="" />
At first I tried to give a warning using this code
$(document).ready(function() {
$("#btn").click(function() {
alert("The button was clicked.");
});
});
But he warned nothing. Is there a way to pass a value from a button to an input value?
source
share