richei Posted August 14, 2013 Share Posted August 14, 2013 Confusing, I know. I have a form in a php loop as that gets its information from a php script. Below is the code for the looped form. Basically, when the index page loads, I click on a menu item and expands a div with the tickets already loaded (which is what the code below retrieves). I click on an icon and it expands a table row with a message box and lot of hidden inputs. <td style="width: 25px; padding-right: 10px;"><?php echo $new; ?></td> <td style="width: 100px; padding-right: 10px;"><?=date('m/d/Y', strtotime($r['createdon']))?></td> <td style="width: 30px; padding-right: 10px;"><?php echo $status; ?></td> <td style="width: 200px; padding-right: 10px;"><?php echo $r['email']; ?></td> <td><?php echo truncate(stripslashes($r['subject'])); ?></td> <td style="width: 200px;"><?=date('m/d/Y', strtotime($r['date']))?> @ <?=date('h:i:s a', strtotime($r['date']))?></td> <td style="width: 120px;" nowrap="nowrap"><?php echo $ans; ?></td> <td style="width: 25px; padding-right: 10px;"> <a href="#<?=$i?>" onclick="ShowEdit('<?=$i?>')"> <img src="images/icn_edit.png" title="Edit News" alt="Edit News" border="0" /></a> <input type="image" src="images/icn_trash.png" title="Trash"> </td> </tr> <!-- this is your drop down row put what you want in here --> <tr style="display:none;" id="<?=$i?>" > <td colspan="8"> <a name="<?=$i?>"></a> <table cellpadding="1" cellspacing="1" border="0" width="100%" id="inq_tab"> <tr> <td colspan="3" height="100" valign="top"> <div style="height: 100px; overflow: auto; padding-top: 5px; padding-left: 5px;background-color:#EEEEEE; border:1px solid #dddddd;"> <?=nl2br(strip_slashes_recursive($r['message']))?> </div> </td> </tr> </table> <br /> <div style="width: 99.5%;"> <form action="" method="post" name="myform"> <div style="float: left; width: 90px; margin: 0 auto;"> <input type="submit" name="close" value="close message" /> </div> <div style="float: right;"> <select name="danswer" id="danswer" > <?php $ans = mysql_query("SELECT * FROM venzo_contactus_answers") or die(mysql_error()); while($row = mysql_fetch_array($ans)) { echo "<option value='$row[id]'>$row[name]</option>"; } unset($row); ?> </select> <input type="button" id="a_select" name="select" value="Select" onclick="ajaxFunction();"/> <input type="hidden" name="id" value="<?=$id?>" /> <input type="hidden" name="req_id" value="<?=$r['req_id']?>" /> </div> </form> </div> <div style="clear: both;"> </div> <form id="subticket_<?=$i?>" method="POST" action="inc/ajax_process_ticket.php" > <input type="hidden" id="id_<?=$i?>" name="id" value="<?=$r['id']?>" /> <input type="hidden" id="cemail_<?=$i?>" name="cemail" value="<?=$r['email']?>" /> <input type="hidden" id="req_id_<?=$i?>" name="req_id" value="<?=$r['req_id']?>" /> <input type="hidden" id="u_name_<?=$i?>" name="u_name" value="<?=$r['name']?>" /> <input type="hidden" id="a_name_<?=$i?>" name="a_name" value="<?=$_SESSION['adminname']?>" /> <input type="hidden" id="div_id_<?=$i?>" value="<?=$i?>" /> <textarea style="width: 99%;" rows="11" name="n_answer" id="n_answer_<?=$i?>"><?=strip_slashes_recursive($read)?></textarea> <div align="center" style="width: 100%;"><input type="button" id="igjo" name="igjo" value="Answer" onclick="processTicket()" /></div> </form> </td> </tr> <!-- end drop down row --> <?php $i++; } and here's the js <script type="text/javascript"> function processTicket() { var element = $(this); var Id = element.attr("id"); var req_id = $("#req_id_"+Id).val(); console.log(req_id); var data = 'req_id=' + req_id; //var data = $("#subticket").serializeArray(); var request = $.ajax({ url: 'inc/ajax_process_ticket.php', type: "post", data: data }); request.done(function(msg) { console.log(data); //alert(msg); }); request.fail(function(jqXHR, textStatus) { console.log(data); //alert("Request Failed:" + textStatus); }); } </script> I've been having a lot of trouble with this script from the beginning, but that was due to this being my first script that I've written. I was having a lot of trouble getting any sort of value, but was worked out - until I realized that the information I was getting was for the wrong post. Then I realized why - each form had the same name, along with each input/textarea ids. And that's probably why I was having such a hard time getting any data to show up. So I gave each one a unique id. That leads me to my current issue - how to select the current selectors for the form i'm using. I know what I need to do, but don't know how to do it. If someone can help me out, i'd be extremely happy. Quote Link to comment https://forums.phpfreaks.com/topic/281152-getting-values-from-1-copy-of-multple-copies-of-the-same-form/ Share on other sites More sharing options...
Solution richei Posted August 15, 2013 Author Solution Share Posted August 15, 2013 Got it fixed, on to other problems now. Quote Link to comment https://forums.phpfreaks.com/topic/281152-getting-values-from-1-copy-of-multple-copies-of-the-same-form/#findComment-1445100 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.