Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jul 2007
    Posts
    571
    Thanks
    25
    Thanked 28 Times in 28 Posts

    PHP with JavaScript

    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):
    Code:
    <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):
    Code:
    <?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>

  • #2
    Regular Coder
    Join Date
    Jan 2006
    Posts
    189
    Thanks
    1
    Thanked 0 Times in 0 Posts
    try:

    PHP Code:
    <?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>

  • #3
    Regular Coder
    Join Date
    Jul 2007
    Posts
    571
    Thanks
    25
    Thanked 28 Times in 28 Posts
    I think you ment
    PHP Code:
    <?php echo $value?>
    and yes, just adding the semi colon which I forgot worked fine

  • #4
    Regular Coder
    Join Date
    Jan 2006
    Posts
    189
    Thanks
    1
    Thanked 0 Times in 0 Posts
    yea sorry, mistyped there :P glad you got it working


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •