473,509 Members | 2,457 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to pass value of a nachor tag

32 New Member
I want that when a user click on a link The value of the anchor tag should pass on to yhe next page.
suppose there is a tag like this:
<a href="">Click Here</a>
I want that 'Click Here' should be stored in a variable.
How can I do this?
Mar 16 '07 #1
5 9482
quill
12 New Member
I want that when a user click on a link The value of the anchor tag should pass on to yhe next page.
suppose there is a tag like this:
<a href="">Click Here</a>
I want that 'Click Here' should be stored in a variable.
How can I do this?
You would do something like this:

Expand|Select|Wrap|Line Numbers
  1. <a href="page.php?message=hi">Message</a>
  2.  
The text inbetween the <a> tags is not passed, what is passed is after the question mark ("message"), which in this example equals "hi".

And in page.php you would get the message by

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. echo $_GET['message'];
  3. ?>
  4.  
Mar 16 '07 #2
Atli
5,058 Recognized Expert Expert
Hi.

The suggestion quill posted is probbly the simplest way, which I use quite frequently myself.

There are more complex ways, however, using javascript and / or Ajax.

Just for fun, this a way to complex way to do what you need.
[PHP]
<script language="javascript">

function send_tag(id)
{
// Create form
var form = document.createElement("form");
form.setAttribute("action", "#");
form.setAttribute("method", "post");

// Create element
var elem = document.createElement("input");
elem.setAttribute("type", "hidden");
elem.setAttribute("name", id);
elem.setAttribute("value", document.getElementById(id).innerHTML);

// attach the elements
form.appendChild(elem);
document.body.appendChild(form);

// submit
form.submit();

// Delete the form
document.body.removeElement(form);
}

</script>

<a id="link" href="#" onClick="javascript: send_tag(getAttribute('id'));">I will be passed</a>

<p>
<?php

if(isset($_POST['link']))
{
echo "Passed data = ". $_POST['link'];
}

?>
</p>[/PHP]
Mar 17 '07 #3
anuragpj
32 New Member
You would do something like this:

Expand|Select|Wrap|Line Numbers
  1. <a href="page.php?message=hi">Message</a>
  2.  
The text inbetween the <a> tags is not passed, what is passed is after the question mark ("message"), which in this example equals "hi".

And in page.php you would get the message by

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. echo $_GET['message'];
  3. ?>
  4.  
It is not working.
page.php does not print anything.
Mar 19 '07 #4
wheel54321
1 New Member
What quill meant is:

Expand|Select|Wrap|Line Numbers
  1. <!-- save this as valuepage.php -->
  2.  
  3. <?php
  4. $value = "This is kool, man";
  5. ?>
  6. <a href="page.php?message=<?php echo $value; ?>">Message</a>
  7.  
  8. <!-- end of valuepage.php -->
  9.  
  10. <!-- now save this as page.php -->
  11.  
  12. <?php
  13. echo $_GET['message'];
  14. ?>
  15. <!-- when clicking on Message, you will get a new page.php 
  16. displaying the $value -->
  17.  
Mar 20 '07 #5
srijan2005
4 New Member
It is not working.
page.php does not print anything.

hey anuragpj ....the code is runing properly...plz chek it out...
Apr 23 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

5
3117
by: Seeker | last post by:
Newbie question here... I have a form with some radio buttons. To verify that at least one of the buttons was chosen I use the following code ("f" is my form object) : var btnChosen; for...
4
3393
by: z_learning_tester | last post by:
I'm reading the MS press C# book and there seems to be a contradiction. Please tell me which one is correct, 1 or 2. Thanks! Jeff 1. First it gives the code below saying that it prints 0 then...
4
2276
by: Jon Slaughter | last post by:
I'm reading a book on C# and it says there are 4 ways of passing types: 1. Pass value type by value 2. Pass value type by reference 3. Pass reference by value 4. Pass reference by reference. ...
14
20369
by: Abhi | last post by:
I wrote a function foo(int arr) and its prototype is declared as foo(int arr); I modify the values of the array in the function and the values are getting modified in the main array which is...
4
9098
by: kinaxx | last post by:
Hello, now I'm learning progamming language in university. but i have some question. in textbook. says there are four passing Mechanism 1) pass by value (inother words : call by value) 2)...
11
9447
by: kinaxx | last post by:
Hello, now I'm learning progamming language in university. but i have some question. in textbook. says there are four passing Mechanism 1) pass by value (inother words : call by value) 2)...
10
13609
by: Robert Dailey | last post by:
Hi, I noticed in Python all function parameters seem to be passed by reference. This means that when I modify the value of a variable of a function, the value of the variable externally from the...
6
2698
by: lisp9000 | last post by:
I've read that C allows two ways to pass information between functions: o Pass by Value o Pass by Reference I was talking to some C programmers and they told me there is no such thing as...
12
11007
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms....
0
7233
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7135
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7342
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
5060
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3215
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3201
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1570
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
774
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
440
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.