tags:

views:

32

answers:

3

I have the following code

<a href="process.html">cholera</a>

I want to pass cholera to process.html onClick. Is there any way to do that in HTML?

If no, PHP scripts are also most welcome.

+4  A: 
<a href="process.html?foo=cholera">cholera</a>
David Dorward
+3  A: 

In pure HTML, only by pre-populating the link with the correct value:

<a href="process.html?name=cholera">cholera</a>

for anything that fetches the link's contents automatically, you would have to use JavaScript. This is comparably easy to do in jQuery. (Update: @James M presents a simple and nice non-jQuery solution in his answer.)

On the receiving end, though, you are going to need some kind of server language (or JavaScript) to do anything with the passed argument.

Pekka
+4  A: 

This will only work if the user has JavaScript enabled, but it might be what you had in mind...

<a href="process.html" onclick="this.href += '?' + encodeURIComponent(this.innerHTML);">cholera</a>
James M.
This is fine, but the innerHTML will need escaping using `encodeURIComponent()`.
Pekka
Good call. I've added it to the (now even more unwieldy) example. :)
James M.
It's still simple and doesn't need any frameworks. +1
Pekka
It would be easier to process in PHP if you added a `thingy=` between the question mark and the data.
David Dorward