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
https://forums.phpfreaks.com/topic/60769-php-table-cell-onclick/
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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.