Jump to content

PHP table cell onclick


screechyboy

Recommended Posts

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?

Link to comment
Share on other sites

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>

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.