screechyboy Posted July 19, 2007 Share Posted July 19, 2007 Im trying to change the value of a PHP variable using the javascript onclick command... <td onclick="<?php $color="white" ?> </td> <?php echo $color ?> Problem is it dosnt wait for onclick before executing the PHP code so as soon as i load the page is writes the variable. I hope that makes sense! is there anywhay around this? Quote Link to comment Share on other sites More sharing options...
chigley Posted July 19, 2007 Share Posted July 19, 2007 PHP is server side, look into AJAX and Javascript Quote Link to comment Share on other sites More sharing options...
screechyboy Posted July 19, 2007 Author Share Posted July 19, 2007 the reason i am trying to do this is i need the color of that table to be passed into a database eventually. Quote Link to comment Share on other sites More sharing options...
chigley Posted July 19, 2007 Share Posted July 19, 2007 Either use AJAX or set a hidden form value and have it as a form which hands the data to PHP. Quote Link to comment Share on other sites More sharing options...
screechyboy Posted July 19, 2007 Author Share Posted July 19, 2007 so would you use Javascript to populate the form text field and then use PHP to post this information? Quote Link to comment Share on other sites More sharing options...
dbo Posted July 19, 2007 Share Posted July 19, 2007 chigley is correct. without knowing it (probably) you're attempting to do stuff that is more ajax related in nature. what you might try doing is putting some stuff into a hidden input field. <input type="hidden" name="color" id="color" value="white" /> doing this you would be able to access the contents of the color for inserting into a database later. if you need to change the color at run time youre either going to have to deal with postbacks or use some javascript to change the value of the color field on the client. for example: <script type="text/javascript">document.getElementById('color').value = "red"; </script> 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.