I have the below code that im trying to add the search results to a div by clicking on the result. Let me know if anyone can assist, I looked at the code about a hundred times and can’t seem to figure out why it wont work. I have tried placing the javascript below the div, below the body, and in the head, no dice. Below is the PHP, javascript, and HTML. Thanks.
Javascript:
<script type="text/javascript">
var oButton = document.getElementById('addData');
var data = document.getElementById('dataInput');
var display = document.getElementById('display');
oButton.onclick = function() {
display.innerHTML += data.value + "<br />";
}
</script>
PHP:
echo '<button id="addData">','<input id="dataInput" type="hidden" value="'.$results_row['username'].'" />','<div id="testt">', '<h3>', $results_row['username'],'</h3>','</div>','</button>';
HTML:
<div id ="search_results"></div>
<p>
<div id="display"></div>
</p>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="search.js"></script>
If you can get the result in server-side code then below code should be the solution. try it.