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 2 of 2

Thread: Form Conversion

  1. #1
    New Coder
    Join Date
    Dec 2005
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Form Conversion

    I'm trying to create a script that does conversions (i.e Celcius to Farenheit). I am writing it in JavaScript, but was wondering if I could do it in PHP. If so, how would I go about doing it? I am new to PHP.

  • #2
    Regular Coder ralph l mayo's Avatar
    Join Date
    Nov 2005
    Posts
    951
    Thanks
    1
    Thanked 31 Times in 29 Posts
    I'd probably do it in Javascript so the page wouldn't have to be reloaded to see the answer, but simple math is pretty much the same either way, most or all of your Javascript should transfer with nothing more than adding dollar signs to the variables.

    PHP Code:
    function CtoF($C)
    {
        return 
    $C * (9/5) + 32;
    }
    echo 
    CtoF(100); // 212 
    Code:
    function CtoF(C)
    {
        return C * (9/5) + 32;
    }
    document.getElementById('answer').innerHTML = CtoF(100); // 212


  •  

    Posting Permissions

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