noobstar Posted September 28, 2007 Share Posted September 28, 2007 Hi what im tring to do is basically this: I have 2 radio buttons if one is clicked it goes to one function and is supposed to set a variable to a value. If the other radio button is clicked it goes to another similar function and is supposed to set the same variable to something else though. This works only for one but not the other for some reason, below is the code. Thank you for any help in adv. Javascript: <SCRIPT LANGUAGE='JavaScript'> <!-- Begin redirTime = '2000'; redirURL = 'http://www.test.test.com/shout.php'; function artpickOut() { <?php $artpick = "Outside Article"; ?> self.setTimeout('self.location.href = redirURL;',redirTime); } function artpickMy() { <?php $artpick = "My Article" ?> self.setTimeout('self.location.href = redirURL;',redirTime); } // End --> </script> My radio buttons: <input type="radio" name="optArtPick" value="Outside Article" onClick="artpickOut()">Outside Article <input type="radio" name="optArtPick" value="My Article" onClick="artpickMy()">My Article thanks again! Quote Link to comment Share on other sites More sharing options...
deadimp Posted September 28, 2007 Share Posted September 28, 2007 You're getting confused in the ways PHP and Javascript are processed. PHP (PHP: Hypertext Preprocessor) is a server side language. That means that all of that your code is executed and outputted before the file is sent to the client. Javascript is a client side language, meaning that the code is executed at the client's side, hence it's executed after the file is sent, after any server-side processing takes place. In this context, PHP executes all of the PHP code first, and then sends it off: Try putting this line at the end of your code: <?=$artpic?> or <?php echo $artpic?> If you notice, it'll always output the last thing you set it to, "My Article". That's simply the way the code is executed. Try using GET variables (url query). Example: (you don't really need javascript, or radio inputs for that matter) <a href='test.php?var=outside'>Outside Article</a><br> <a href='test.php?var=my'>My Article</a> test.php: <?php $var=$_GET['var']; //This gets the variable from the query if ($var=='outside') echo "Outside article"; else if ($var=='my') echo "My article"; ?> Quote Link to comment Share on other sites More sharing options...
noobstar Posted September 28, 2007 Author Share Posted September 28, 2007 Thanks alot man Quote Link to comment 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.