I have a javascript function that reformats a link. When a HREF link is clicked, I need to execute this method to finish creating the HREF.
Example JS method:
function fixURL (dest, val){
return dest + val;
}
I have an regular HREF and would like to combine the result of the above method to create:
<a href="http://www.site.com/" + fixURL('poo','no')>Click me!</a>
Is this possible and is it ideal to do so?
You can use an
onclickhandler. Note, you’re generally better off not using inline event handlers likeonclick="something...", so this is just for demonstration purposes.Also, this will try to open a new window/tab with the search result.
http://jsfiddle.net/sxtuz/1/
The same effect, only using DOM event handlers. Note the
id="fixme"attribute.http://jsfiddle.net/sxtuz/