Note that there are some explanatory texts on larger screens.

plurals
  1. POEcho data in class in which button was clicked
    text
    copied!<p>This is an ajax function that i would like carry out on click of a button in a specific class , many of the same classes are generated from a while loop in php, however i want the data to be outputted only in the class in whitch the button was clicked, not the other classes although they have the same name.</p> <p>I also need to change the ajax function as "status" is a class not an id whereas the function calls elements of ID "status" not class "status", an</p> <pre><code>&lt;script&gt; function ajax_posta() { // Create our XMLHttpRequest object var hr = new XMLHttpRequest(); // Create some variables we need to send to our PHP file var url = "javas.php"; hr.open("POST", url, true); // Set content type header information for sending url encoded variables in the request hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); // Access the onreadystatechange event for the XMLHttpRequest object hr.onreadystatechange = function () { if (hr.readyState == 4 &amp;&amp; hr.status == 200) { var return_data = hr.responseText; document.getElementById('status').innerHTML = return_data; } } // Send the data to PHP now... and wait for response to update the status div hr.send("num=" + (--num)); // Actually execute the request document.getElementById('status').innerHTML = "&lt;img src = 'loading.gif' height = '30' width = '30'&gt;"; } $(document).ready(function() { $('.eventer.button').click(function () { var self = this; $.post('javas.php', function (data) { $(self).parent('div').find('.status').html(data); }) }); } ) ; &lt;/script&gt; </code></pre> <p>PHP code in the while loop, generates multiple duplicates of the class and buttons with the same name.</p> <pre><code>echo " &lt;div class = 'eventer'&gt; $timeposted &lt;br&gt;$eventlist &lt;input name='myBtn' type='submit' value='increment' onClick='javascript:ajax_post();'&gt; &lt;input name='lol' type='submit' value='dec' onClick='javascript:ajax_posta();'&gt;&lt;/div&gt; &lt;div class = 'status'&gt;&lt;/div&gt;"; echo "&lt;br&gt;"; </code></pre> <p>What i have so far does not seem to work, any help is appreciated, thanks!</p>
 

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