PDA

View Full Version : newbie, call function from anchor onClick?



daxtrajero
04-05-2012, 10:52 AM
Hi Guys

Just want a bit of quick advice. So far in my adventures with Javascript I've used form inputs to pass parameters to my javascript functions, using the input's VALUE field.

I'm wondering if it's possible to do the same with an anchor tag ? I'm guessing as there's no VALUE field, I can pass the paramter in the function call itself eg.

Eg. to pass the parameter value 22 to myFunction....

<a href="#" onClick="myFunction(22)">TEST</a>

Is this OK ?

vwphillips
04-05-2012, 12:06 PM
<a href="#" onClick="myFunction(22);return false'
;">TEST</a>

you will need the return false; to prevent the page reloading

daxtrajero
04-05-2012, 06:42 PM
<a href="#" onClick="myFunction(22);return false'
;">TEST</a>

you will need the return false; to prevent the page reloading

thanks mate - that'll explain why my tests so far haven't been working, d'oh!