alohatofu Posted April 22, 2007 Share Posted April 22, 2007 Hello, I have a link say <a href="javascript:freak_new()">click link </a> If i have varaibles that I want to carry with that link how would I do it? I can't use <a href="javascript:freak_new()?var=2783"> can't I? Thanks Link to comment https://forums.phpfreaks.com/topic/48163-carry-variable-with-javascript/ Share on other sites More sharing options...
AndyB Posted April 22, 2007 Share Posted April 22, 2007 <a href="javascript:freak_new(2783)"> might work if the js function can use 2783 Link to comment https://forums.phpfreaks.com/topic/48163-carry-variable-with-javascript/#findComment-235462 Share on other sites More sharing options...
alohatofu Posted April 22, 2007 Author Share Posted April 22, 2007 so can i use <a href="javascript:freak_new(<?php $number ?>)"> ? Link to comment https://forums.phpfreaks.com/topic/48163-carry-variable-with-javascript/#findComment-235465 Share on other sites More sharing options...
dwees Posted April 22, 2007 Share Posted April 22, 2007 Avoid use of the word JavaScript in your href's. Instead, use an href like #, and put your code for the function in the onclick attribute of your link. To answer your question, what you are suggesting will work, except you need to use <a href="#" onclick="return freak_new(<?php echo $number ?>)">Click me</a> If you use something like this format, you can return false, and cancel the link (if you need to). If you return true, the link goes through. Dave Link to comment https://forums.phpfreaks.com/topic/48163-carry-variable-with-javascript/#findComment-235558 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.