Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I return an id value from a div already populated through ajax
    text
    copied!<p>I am having some difficulty passing a correct id function back to AJAX. I'm creating a product bulletin generator that lets items to be added by their SKU code (which works fine). My problem is that when a bulletin is clicked on, a preview of that bulletin is loaded into a div and shows all products associated with that bulletin.<br> From inside those results, I am trying to add the ability to delete a product from the bulletin. The problem is that the value being passed back to AJAX belongs to the first product only. It won't send the value belonging to the particular item if it is any other item than the first one.</p> <p>This is the code (belonging to main.php) that gets loaded via AJAX into a div and is looped with each product associated with a selected bulletin</p> <pre><code> echo "&lt;form name='myDelForm'&gt; $news_gen_id&lt;br&gt; &lt;input type='hidden' id='delccode' value='".$news_gen_id."'&gt; &lt;input type='hidden' id='deledit' value='".$edit."'&gt; &lt;input type='button' onclick='ajaxDelCcode()' value='Delete' /&gt;&lt;br&gt;&lt;/form&gt; &lt;/td&gt;"; </code></pre> <p>The AJAX code (on index.php, where the div that calls in main.php is also located) is this</p> <pre><code>function ajaxDelCcode(){ var ajaxRequest; // The variable that makes Ajax possible! try{ // Opera 8.0+, Firefox, Safari ajaxRequest = new XMLHttpRequest(); } catch (e){ // Internet Explorer Browsers try{ ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try{ ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ // Something went wrong alert("Your browser broke!"); return false; } } } // Create a function that will receive data sent from the server ajaxRequest.onreadystatechange = function(){ if(ajaxRequest.readyState == 4){ var ajaxDisplay = document.getElementById("ajaxMain2"); ajaxDisplay.innerHTML = ajaxRequest.responseText; } } var deledit = document.getElementById("deledit").value; var delccode = document.getElementById("delccode").value; var queryString = "?delccode=" + delccode + "&amp;deledit=" + deledit; ajaxRequest.open("GET", "main.php" + queryString, true); ajaxRequest.send(null); } //--&gt; &lt;/script&gt; </code></pre> <p>Currently, using those two pieces of code, I can successfully delete only the first product. The delccode variables do not seem to change when the products are looped (although when I echo the variables during the loop, it is definitely changing to the appropriate value...it's just not passing it correctly back to AJAX.)</p> <p>I tried taking the AJAX code, putting it inside the main.php product loop, and change the function name during each loop (so ajaxDelCcode$news_gen_id() for example) and also to the button itself so that it is calling the AJAX specific to it. And it works if you are visiting main.php directly...but not from index.php after main.php has been called into the div.</p> <p>I can't figure out how to pass the correct looped value from main.php within the div, back to the AJAX code on index.php</p> <p>Can anyone help me with this?</p> <p>Thanks,</p> <p>Dustin</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