My onclick()
function to fetch a button's value to a text box is working only one time. Here is a JQuery function to add the button's value to an input text box
$("button").click(function() {
var fired_button = $(this).val();
var word = document.getElementById("str").value + ' ' + fired_button;
document.getElementById("str").value = word;
});
HTML code
<button class="btn m-1 btn-secondary" id="sel0" value="<?php echo $row2['W1']; ?>"><?php echo
row2['W1']; ?> </button>
<button class="btn m-1 btn-secondary" id="sel1" value="<?php echo $row2['W2']; ?>"><?php echo
$row2['W2']; ?></button>
<button class="btn m-1 btn-secondary" id="sel2" value="<?php echo $row2['W3']; ?>"><?php echo
$row2['W3']; ?></button>
<button class="btn m-1 btn-secondary" id="sel3" value="<?php echo $row2['W4']; ?>"><?php echo
$row2['W4']; ?></button>
After clicking the start button it's working fine and displaying the values of the clicked button in the textbox
But after I fetch the next row in the query, the AJAX values are being changed and the onclick
function is not working.
It's a quiz project. I want onclick
to fetch the button value into the textbox, which is working right on the first call. But, after fetching the second row by clicking next button, then it's not working.