Note that there are some explanatory texts on larger screens.

plurals
  1. POpassing tag id from php to javascript
    primarykey
    data
    text
    <p>Hie: i have managed to display multiple Divs using a foreach statement in php (the divs show different rows from a Database), and each of these Divs have a form at the bottom whose button evokes the javascript onclick function below.</p> <pre><code> function SubmitForm(msg) { var cid = $("#cid").val(); var message = $("#"+msg).val(); $.post( "picturecomments.php", { cid: cid, message: message }, function(data) {alert(data);} ); } </code></pre> <p>and below is the form</p> <pre><code>&lt;form action="picturecomments.php" method="post"&gt; &lt;span &gt; &lt;input type="hidden" name="cid" id="cid" value="',$result['id'],'"required="required"/&gt; &lt;textarea name="'.$message.'" id="'.$message.'" style="width:85%; height:25px; margin:0px;" placeholder="give a comment" required="required"&gt;&lt;/textarea&gt; &lt;input type="button" onclick="SubmitForm('.$message.');" id="searchForm"style="width:5%; height:25px; margin:0px;" value="Send"/&gt; &lt;/span&gt; &lt;/form&gt; </code></pre> <p>my problem is when i try to click the send button, it always listens to the first div, so i have noticed that the problem is because i have just one ID FOR THESE TAGS AND WHEN THE SCRIPT RUNS, IT FINDS ONLY THE FIRST id...</p> <p>how do i make the function run for multiple ids? because when i have 2 divs, the function will only listen to the first form submit</p> <p>the $message variable is within the same php code, i have done my research but i am failing to find a solution</p> <p>PLEASE HELP!!</p>
    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