troubleshooting Question

php jquery post multiple forms on the same page but results into seperate div elements

Avatar of Robert Saylor
Robert SaylorFlag for United States of America asked on
AJAXPHP
4 Comments1 Solution1178 ViewsLast Modified:
I want to handle this process multiple of times on the same page. So I gave <div id="show"> a unique by appending "show" using php. However, when I submit the form from section 1 or section 2 it updated both show_1 and show_2.

Any suggestions?

<form action="script.php">
<input name="field1" value="123" type="radio" checked="checked" />
<input name="field2" value="456" type="hidden" />
<input name="field3" value="789" type="text" />
<input type="submit" value="post my form" />
</form>
<script>
$("form").submit(function(event) {
   event.preventDefault();
   $.post($(this).attr("action"),$(this).serializeArray(), function(php_msg) { $("#show_4").text(php_msg); });
})
</script>
<div id="show_4"></div>

2nd form on same page:

<form action="script.php">
<input name="field1" value="123" type="radio" checked="checked" />
<input name="field2" value="456" type="hidden" />
<input name="field3" value="789" type="text" />
<input type="submit" value="post my form" />
</form>
<script>
$("form").submit(function(event) {
   event.preventDefault();
   $.post($(this).attr("action"),$(this).serializeArray(), function(php_msg) { $("#show_5").text(php_msg); });
})
</script>
<div id="show_5"></div>
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros