Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to refresh contents of div after link is clicked
    primarykey
    data
    text
    <p>I have a form which contains a dropdown box, when the value is changed the form uses jQuery and ajax to produce a table. The table contains data based on the value of the dropdown box and also links.</p> <p>My initial script which is where the dropdown box is and where the table is added is:</p> <pre><code>&lt;?php require_once('/connections/db.php'); mysql_select_db($database_db, $db); $query_weeks = "SELECT WeekNo, WeekName FROM tbl_weeks ORDER BY WeekNo ASC"; $weeks = mysql_query($query_weeks, $db) or die(mysql_error()); $row_weeks = mysql_fetch_assoc($weeks); $totalRows_weeks = mysql_num_rows($weeks); ?&gt; &lt;!DOCTYPE HTML&gt; &lt;html&gt; &lt;head&gt; &lt;meta charset="utf-8"&gt; &lt;title&gt;Untitled Document&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;form name="form1" method="post" action=""&gt; &lt;select id="weekselect" name="week"&gt; &lt;?php do { ?&gt; &lt;option value="&lt;?php echo $row_weeks['WeekNo']?&gt;"&gt;&lt;?php echo $row_weeks['WeekName']?&gt;&lt;/option&gt; &lt;?php } while ($row_weeks = mysql_fetch_assoc($weeks)); $rows = mysql_num_rows($weeks); if($rows &gt; 0) { mysql_data_seek($weeks, 0); $row_weeks = mysql_fetch_assoc($weeks); } ?&gt; &lt;/select&gt; &lt;/form&gt; &lt;div id="mydata"&gt;&lt;/div&gt; &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $(document).ready(function (){ // listen to change in monthselect $('#weekselect').change(function(){ var week= $('#weekselect option:selected').val(); //pass val to php $.post('test2.php',{week: week}, function(data) { //do something with the data $('div#mydata').html(data); }); }); }); &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>The script produces the dropdown from the mysql db and creates a listener for it, when the select is changed the value of the select is passed to the test2.php using jquery. the data returned is added to div #mydata</p> <p>Test2 which produces the table is as follows</p> <pre><code>&lt;?php if (!isset($_SESSION)) {session_start();} include('session.php'); require_once('Connections/dbc.php'); $open_week=$_SESSION['MM_OpenWeek']; $week_selected=$_POST['week']; $season=$_SESSION['MM_Season']; ?&gt; &lt;!DOCTYPE HTML&gt; &lt;html&gt; &lt;head&gt; &lt;meta charset="utf-8"&gt; &lt;title&gt;Untitled Document&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;?php echo '&lt;p&gt;Week selected: '.$week_selected .'&lt;p&gt;'; echo '&lt;p&gt;Open Week: '.$open_week .'&lt;p&gt;'; if ($week_selected&gt;=$open_week) { echo '&lt;p&gt;Week Open&lt;p&gt;'; } else { echo '&lt;p&gt;Week Closed&lt;p&gt;'; } //create recordset of fixtures for the week selected $sql="SELECT * FROM q_games_stats WHERE WeekNo =".$week_selected . " and Season=". $season ." and at='Home' ORDER BY WeekNo ASC"; $rec_games=mysqli_query($dbc,$sql); //create table using the recordset ?&gt; &lt;div id="data_table"&gt; &lt;table class="table" align="center"&gt; &lt;th class="th" width="80px"&gt;Match Date&lt;/th&gt; &lt;th class="th" width="150px"&gt;Home Team&lt;/th&gt; &lt;th class="th" width="40px"&gt;Score&lt;/th&gt; &lt;th class="th" width="150px"&gt;Away Team&lt;/th&gt; &lt;th class="th" width="150px"&gt;Link&lt;/th&gt; &lt;?php while ($row=mysqli_fetch_array($rec_games)) { ?&gt; &lt;tr class="tr"&gt; &lt;td class="td"&gt;&lt;?php echo $row['MatchDate']?&gt;&lt;/td&gt; &lt;td class="td"&gt;&lt;?php echo $row['TeamName']?&gt;&lt;/td&gt; &lt;td class="td"&gt;&lt;?php echo $row['Score']?&gt;&lt;/td&gt; &lt;td class="td"&gt;&lt;?php echo $row['OppName']?&gt;&lt;/td&gt; &lt;td class="td"&gt;&lt;a href="#" target="_top"&gt;Link&lt;/a&gt;&lt;/td&gt; &lt;/tr&gt; &lt;?php } ?&gt; &lt;/table&gt; &lt;/div&gt; &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $(document).ready(function (){ // listen to change in monthselect $('#data_table a').click(function(){ alert("link clicked"); }); }); &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>This produces the table, which includes links. There is an event listener of the links in the table, which when I click produces an alert.</p> <p>What I want to do is instead of an alert being produced when clicking a link is for the table to reproduce, the reason for this is when the user clicks a link it will run a script which will change the underlying data in the table and therefore the table will need to be refreshed.</p> <p>Is there I way I can do this, or is there a better way to do what I want to do?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload