0
<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!

Simon Suh
  • 10,599
  • 25
  • 86
  • 110

2 Answers2

2

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

<a href="#" onclick="size( 'x' ); return false;">HTML Link</a>
charliegriefer
  • 3,342
  • 1
  • 18
  • 20
1

Passing JavaScript Variable to A HREF

Community
  • 1
  • 1
simshaun
  • 21,263
  • 1
  • 57
  • 73