Jump to content

Question about php/javascript


Patrick3002

Recommended Posts

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.