Note that there are some explanatory texts on larger screens.

plurals
  1. PO<button> Same Button, Multiple Locations, Different Code
    primarykey
    data
    text
    <p>I am writing an application in JQTouch, and am using a big red button </p> <pre><code>&lt;a href="#" class="redButton"&gt;Red&lt;/a&gt; </code></pre> <p>I am using PHP to dynamically build the JQT page with multiple divs. The app is a server management console that gets data from MySQL. My idea is that I use a While loop to make a div for each server returned in the MySQL query, and each div will have a delete server button(the big red button). I have to call the dame bit of code because of the whole dynamic page generating thing. So I was wondering if there was a way I could have the onClick function that I call with the button Red know what div the button is in that is calling the function. There will be a button in multiple divs that call the same code, but i have to know WHAT server to delete. Any suggestions?</p> <p>Here is the full source code.</p> <pre><code>&lt;html&gt; &lt;link rel="stylesheet" href="jq_touch/themes/css/jqtouch.css" title="jQTouch"&gt; &lt;script src="jq_touch/src/lib/zepto.min.js" type="text/javascript" charset="utf-8"&gt;&lt;/script&gt; &lt;script src="jq_touch/src/jqtouch.min.js" type="text/javascript" charset="utf-8"&gt;&lt;/script&gt; &lt;!-- Uncomment the following two lines (and comment out the previous two) to use jQuery instead of Zepto. --&gt; &lt;!-- &lt;script src="../../src/lib/jquery-1.7.min.js" type="application/x-javascript" charset="utf-8"&gt;&lt;/script&gt; --&gt; &lt;!-- &lt;script src="../../src/jqtouch-jquery.min.js" type="application/x-javascript" charset="utf-8"&gt;&lt;/script&gt; --&gt; &lt;script src="../../extensions/jqt.themeswitcher.min.js" type="application/x-javascript" charset="utf-8"&gt;&lt;/script&gt; &lt;script type="text/javascript" charset="utf-8"&gt; var jQT = new $.jQTouch({ icon: 'jqtouch.png', icon4: 'jqtouch4.png', addGlossToIcon: false, startupScreen: 'jqt_startup.png', statusBar: 'black-translucent', themeSelectionSelector: '#jqt #themes ul', preloadImages: [] }); // Some sample Javascript functions: $(function(){ // Show a swipe event on swipe test $('#swipeme').swipe(function(evt, data) { var details = !data ? '': '&lt;strong&gt;' + data.direction + '/' + data.deltaX +':' + data.deltaY + '&lt;/strong&gt;!'; $(this).html('You swiped ' + details ); $(this).parent().after('&lt;li&gt;swiped!&lt;/li&gt;') }); $('#tapme').tap(function(){ $(this).parent().after('&lt;li&gt;tapped!&lt;/li&gt;') }); $('a[target="_blank"]').bind('click', function() { if (confirm('This link opens in a new window.')) { return true; } else { return false; } }); // Page animation callback events $('#pageevents'). bind('pageAnimationStart', function(e, info){ $(this).find('.info').append('Started animating ' + info.direction + '&amp;hellip; And the link ' + 'had this custom data: ' + $(this).data('referrer').data('custom') + '&lt;br&gt;'); }). bind('pageAnimationEnd', function(e, info){ $(this).find('.info').append('Finished animating ' + info.direction + '.&lt;br&gt;&lt;br&gt;'); }); // Page animations end with AJAX callback event, example 1 (load remote HTML only first time) $('#callback').bind('pageAnimationEnd', function(e, info){ // Make sure the data hasn't already been loaded (we'll set 'loaded' to true a couple lines further down) if (!$(this).data('loaded')) { // Append a placeholder in case the remote HTML takes its sweet time making it back // Then, overwrite the "Loading" placeholder text with the remote HTML $(this).append($('&lt;div&gt;Loading&lt;/div&gt;').load('ajax.html .info', function() { // Set the 'loaded' var to true so we know not to reload // the HTML next time the #callback div animation ends $(this).parent().data('loaded', true); })); } }); // Orientation callback event $('#jqt').bind('turn', function(e, data){ $('#orient').html('Orientation: ' + data.orientation); }); }); &lt;/script&gt;&lt;?php //Connect mysql_connect("localhost", "root", "root") or die(mysql_error()); //Make and store queries mysql_select_db("servermgr") or die(mysql_error()); $result = mysql_query("SELECT * FROM servers") or die(mysql_error()); //Echo some constant HTML echo'&lt;div id="serverset"&gt;'; echo'&lt;div class="toolbar"&gt;'; echo'&lt;h1&gt;Servers Home&lt;/h1&gt; '; echo'&lt;/div&gt;'; echo'&lt;ul class="rounded"&gt;'; //Begin printing out MYSQL rows (List Items) while($row = mysql_fetch_array( $result )) { //$row_friendlyName = $_row['friendly_name'] $friendlyName_noSpaces = str_replace(' ', '_', $row[friendly_name]); echo'&lt;li class=""&gt;&lt;a href="#'.$friendlyName_noSpaces.'"&gt;'.$row["friendly_name"].'&lt;/a&gt;&lt;/li&gt;'; } //Close list echo'&lt;/ul&gt;'; echo '&lt;/div&gt;'; //Redo all previous queries to print out the divs mysql_select_db("servermgr") or die(mysql_error()); $result2 = mysql_query("SELECT * FROM servers") or die(mysql_error()); while($row2 = mysql_fetch_array( $result2 )) { $friendlyName_noSpaces2 = str_replace(' ', '_', $row2[friendly_name]); echo '&lt;div id="'.$friendlyName_noSpaces2.'"&gt;'; echo'&lt;div class="toolbar"&gt;'; echo'&lt;h1&gt;'.$row2[friendly_name].'&lt;/h1&gt; '; echo '&lt;a href="#" class="back"&gt;Back&lt;/a&gt;'; echo'&lt;/div&gt;'; echo'&lt;ul class="rounded"&gt;'; echo '&lt;li&gt;Friendly Name: '.$row2[friendly_name].'&lt;/li&gt;'; echo '&lt;li&gt;IP Address: '.$row2[ip].'&lt;/li&gt;'; echo '&lt;li&gt;Server Hostname: '.$row2[hostname].'&lt;/li&gt;'; echo '&lt;li&gt;MAC Address: '.$row2[MAC].'&lt;/li&gt;'; echo'&lt;/ul&gt;'; echo'&lt;button href="#" class="redButton"&gt;Red&lt;/button&gt;'; echo'&lt;/div&gt;'; } //END OF PHP ?&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    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.
 

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