Patrick3002 Posted August 27, 2007 Share Posted August 27, 2007 Hi, im going to show you an example of what i want to do, then try ang explain it. I have a page http://domain.com/run.php which when i go there i get a submit link, thats all. I have another page, http://domain.com/vote.php. When i click that submit link from /run.php i want it to perform the javascript func on /vote.php: <a href="javascript:vote( 'right' );" border="0">[sUBMIT]</a> When that is clicked on run.php: function vote(side) { document.getElementById("side_voting_on").value=side; var v = false; for (i=0; i<a.length; i++) { if (a[i]==2617072) { v = true; break; } } if (!v) { document.getElementById('vote_form').submit(); } else { location.href = "/vote.php"; } } When the submit link on run.php is clicked, i want the javascript func on vote.php to run. If anyone can help me out with this, that'd be greatly appreciated! ~Patrick Quote Link to comment https://forums.phpfreaks.com/topic/66879-question-about-phpjavascript/ Share on other sites More sharing options...
nathanmaxsonadil Posted August 27, 2007 Share Posted August 27, 2007 if(isset($_REQUEST['submit'])) { echo "<a href="javascript:vote( 'right' );" border="0">[sUBMIT]</a>"; } Quote Link to comment https://forums.phpfreaks.com/topic/66879-question-about-phpjavascript/#findComment-335242 Share on other sites More sharing options...
Patrick3002 Posted August 27, 2007 Author Share Posted August 27, 2007 How does that in anyway link from run.php to vote.php? Read the post again. I need to run the javascript on vote.php FROM run.php by clicking a link or whatever else is easiest. Thanks for the try though! Quote Link to comment https://forums.phpfreaks.com/topic/66879-question-about-phpjavascript/#findComment-335247 Share on other sites More sharing options...
sstangle73 Posted August 27, 2007 Share Posted August 27, 2007 im new to php but couldnt you do something like putting the function on func.php include("func.php"); on both pages then use onsubmit(<?php ... ?>) Quote Link to comment https://forums.phpfreaks.com/topic/66879-question-about-phpjavascript/#findComment-335281 Share on other sites More sharing options...
Patrick3002 Posted September 1, 2007 Author Share Posted September 1, 2007 this sucks, no one knows how i would do this??? Quote Link to comment https://forums.phpfreaks.com/topic/66879-question-about-phpjavascript/#findComment-339100 Share on other sites More sharing options...
Jessica Posted September 1, 2007 Share Posted September 1, 2007 You might look into ajax. Often there is an easier solution to a problem if you just rethink the problem. Why does the javascript have to be on vote.php? Why don't you make it a function and run it on any page you want? Why are you making it more difficult than just regular javascript? Quote Link to comment https://forums.phpfreaks.com/topic/66879-question-about-phpjavascript/#findComment-339102 Share on other sites More sharing options...
Patrick3002 Posted September 1, 2007 Author Share Posted September 1, 2007 Thanks, i might look into that. I'm making it that way because thats the way it has to be for the situation at hand. Quote Link to comment https://forums.phpfreaks.com/topic/66879-question-about-phpjavascript/#findComment-339107 Share on other sites More sharing options...
Jessica Posted September 1, 2007 Share Posted September 1, 2007 As I was saying, it doesn't always have to be as hard as it seems. But okay. Check out mootools.net for a cool ajax library Quote Link to comment https://forums.phpfreaks.com/topic/66879-question-about-phpjavascript/#findComment-339110 Share on other sites More sharing options...
pyrodude Posted September 1, 2007 Share Posted September 1, 2007 As was said by jesirose, ajax is a great option, assuming the browser supports it. Another option, if a redirect to vote.php is possible, you can use javascript to check and see that the referrer is run.php. This isn't foolproof, however, as some browsers block that information or allow it to be spoofed. Please also try to have an option available for those surfers who do not have javascript enabled. Quote Link to comment https://forums.phpfreaks.com/topic/66879-question-about-phpjavascript/#findComment-339290 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.