[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 499
  • Last Modified:

JQuery applied to multiple ids

I have a jQuery function
<script type="text/javascript">
            function loadCategory(id) {
                  $("#products").load("sponsor_products.php?chain=$chain&emp=$emp&category="+id+"");
            }
            </script>

I display a list of categories and I want the ability to have the user click on any catergory and have the data retrurned from sponsor_products.php to display immediately BELOW the category name.

I run a loop, in PHP:
while(list($store_category)=mysql_fetch_row($result_products))
            {
      <center><h3><a href="javascript:loadCategory('$store_category')">$store_category</h3></center></a><br><center><div class="products" id="products" style="width: 480px; "></div></center>
            }

This works, except that everything appears in the first div created.

I tried changing the id in the loop to id="products_$store_category" and changing the function to $("#products"."+id+") but it stopped working.

Any ideas on how to have the function place the data in the appropriate div?


I have a jQuery function 
<script type="text/javascript">
		function loadCategory(id) {
			$("#products").load("sponsor_products.php?chain=$chain&emp=$emp&category="+id+"");
		}
		</script>
 
I
while(list($store_category)=mysql_fetch_row($result_products))
		{
	<center><h3><a href="javascript:loadCategory('$store_category')">$store_category</h3></center></a><br><center><div class="products" id="products" style="width: 480px; "></div></center>
		}

Open in new window

0
birwin
Asked:
birwin
1 Solution
 
mstrelanCommented:
$("#products"."+id+")  doesn't look like valid syntax
i dont know what youre trying to do but but the . between the sets of quoted strings is not a concatenator like it is in php...
0
 
prokvkCommented:
The syntax $("#products"."+id+") is completely wrong, write it like this:

$("#products" + id)
0
 
birwinAuthor Commented:
Thank you. I was using PHP syntax. Thank you for giving me the correct JavaScript.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now