...

View Full Version : PHP with JavaScript



srule_
01-10-2008, 10:13 PM
How do I change the value of a form field to a PHP variable. I know how to do it with no PHP. but once I add php it stops working.

NO PHP(WORKS):



<form>
<input id="millitia" type="text" name="militia" size="5" value="0">
<input type="Button" value="T" class="button" onclick="millitia.value=10">
</form>



WITH PHP (Does Not Work):


<?php
$value = 10;
?>

<form>
<input id="millitia" type="text" name="militia" size="5" value="0">
<input type="Button" value="T" class="button" onclick="millitia.value=<?php echo $value ?>">
</form>

king2k5
01-10-2008, 10:40 PM
try:



<?php
$value = 10;
?>

<form>
<input id="millitia" type="text" name="militia" size="5" value="0">
<input type="Button" value="T" class="button" onclick="millitia.value=<?=echo $value; ?>">
</form>

srule_
01-10-2008, 11:33 PM
I think you ment


<?php echo $value; ?>


and yes, just adding the semi colon which I forgot worked fine :thumbsup:

king2k5
01-11-2008, 12:26 AM
yea sorry, mistyped there :P glad you got it working :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum