I wish to put some instructions with a link - onclick calling a script that display a simple alert box. If I did like this...
<label for="arquivo">Máximo de 1MB, observe os <a href="" onclick="ajudaUpload();">tipos permitidos</a>.</label>
the page is reloaded even with a return false, and if I did like this...
<label for="arquivo">Máximo de 1MB, observe os <a href="#" onclick="ajudaUpload();">tipos permitidos</a>.</label>
with the "#" symbol, the page is scrolled to the top and "#" is added to query string. Is there a third way to do it without reloading, scrolling and garbage?
Remove your herf and give id for your tag. Then by using id you can show your alert. ('#id').click(function (){alert(message); return false; });
You can use:
Even I was stuck on a similar problem. I wanted to use onclick function but the page would reload, which I didn't want. I tried href = "javascript:void(0);" and it worked.
and then return false in your function:
Very simple way to do this is just add '?' (questionmark) :)
F.e.
Return false after the call:
Or if your function returns false then you can return the result of the function:
It's not enough to just return false in the function, you need to actually return false from the click handler.
Almost any element suports onclick events, so you can use a b tag, or a button tag, even an span tag. Then you can style it to look just like a link (a tag), or any other way you want. For example: