Click here to Skip to main content
15,880,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to pass div id and query string in anchor tag.
This is my code:
HTML
<a href="#cart?product_name=traditional">Product</a>
<div id="cart">
echo $_GET['product_name'];
?>
</div>

The value is not displaying.
Posted
Updated 4-Oct-12 20:13pm
v2

What about:
HTML
<a href="#cart?product_name=traditional&divId=cart">Product</a>

There are two query strings in it:
1. product_name
2. divId
 
Share this answer
 
Comments
Deepthi.21456 5-Oct-12 2:17am    
I am not getting.Tell me Clearly.
Sandeep Mewara 5-Oct-12 2:45am    
I believe, I was as clear as possible. :doh:

Read about querystrings on what are they are how are they implemented.
Deepthi.21456 5-Oct-12 2:51am    
I Know how to implement.When i did like this,I am getting error like this unexpected token.
You seem to by trying to mix PHP and javascript. The anchor link will not do a postback to the server. So echo $_GET['product_name']; will never be reached when clicking the link.

Switching the element around will work;

<a href="?product_name=traditional#cart">Product</a>

<div id="cart">
<?php
echo $_GET['product_name'];
?>
</div>
 
Share this answer
 
Comments
Deepthi.21456 14-Nov-12 7:07am    
When i did like this the page is reloading.I dnt want reload.How can i do that.
Sebastiaan Meijerink 14-Nov-12 12:31pm    
It's like I thought. You are trying to mix php and javascript. If you do not want the page to refresh you'll have to use an ajax call to get the contents of cart. The php variable will never be refreshed unless you refresh the whole page.

I suggest you read into what ajax is and when you should use it. Try to get a clear notion of what runs on the server and what runs on the client.

To give a solution doesn't make much sense in this form. I'll make an article or tip for you and then post the link here to show the difference.
Deepthi.21456 14-Nov-12 23:24pm    
ok,Thanks For Your Suggestion.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900