I have created a variable in php which when clicked i would like it to populate another table which some data.
I'm guessing i use AJAX and Jquery but what function do i look at?
e.g. if i did something like this. I would like to click $variable1 and only when clicked appear in table1 in .
Does anybody have a link to the function or the few lines of code that can do this? Thanks
<?php
$variable1 = "text";
echo $variable1;
?>
<div id="table1">
<table>
<tr>
<td>variable1 will go here when clicked</td>
There is a lot of way to achieve this:
variable1
in a div a make it appears when clickedvariable1
table1
with variable1
...<?php
$variable1
echo '<a href="#" id="aVar">.$variable1.'</a>';
?>
// Dont forget to include jQuery in the html page. Gra it from the google cdn
<div id="table1">
<table>
<tr>
<td><div id="var1Descr">variable1 will go here when clicked</div></td>
<script>
$(function(){
$("#aVar").click(function(){
var content=$(this).html();
$("#var1Descr").html(content);
});
});
</script>
This code will simply do this
1) When user clicks on the element with id "aVar", it reads the content of the clicked element and store int a variable called content. 2) set the stored content as the content of the div called "var1DEscr".
If you want to load some other data in the second div, you can use jquery ajax to fetch that data from a server page and load as the content of the div
you can use the onclick event of the td.
<div id="table1">
<table>
<tr>
<td onclick="this.innerHtml = <?php echo $variable1?>">variable1 will go here when clicked</td>