Simon Suh
Simon Suh

Reputation: 10882

How do I pass on javascript variables through a html link tag?

<a href="javascript:size('x')">HTML Link</a>

I have the above code in my html file and want to pass on the variable 'x' to my javascript function 'size()'.

In my javascript file, I'm trying to use the variable as follows:

function size(id) 
{
   document.write("hi user number" + id);
}

I think my javascript part is correct and that my html syntax for sending the variable is wrong but having a bit of difficulty googling the correct syntax. Could someone help me here? thnx!

Upvotes: 0

Views: 3694

Answers (2)

charliegriefer
charliegriefer

Reputation: 3382

I think you need a return false in there. Try rewriting the link as:

<a href="#" onclick="size( 'x' ); return false;">HTML Link</a>

Upvotes: 2

Related Questions