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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Aug 2009
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Simple Math Problem

    I am newbie to php and am trying to resolve a simple math problem. I need to take a number and divide it based on the selection of a drop down box. As an example let's say I have a figure like 1000 and a drop down box that has a list of numbers 1 though 15. I would like like to be able to select a number in the drop down box and hit a submit button and the result would be 1000 divided by the number selected.

  • #2
    Regular Coder seco's Avatar
    Join Date
    Nov 2008
    Location
    Oregon
    Posts
    687
    Thanks
    6
    Thanked 79 Times in 77 Posts
    PHP Code:
    <?php
    if(isset($_POST['submit'])){

    $number $_POST['number'];

    echo 
    1000/$number;

    }
    ?>
    Code:
    <form action="" method="post">
    <select name="number">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    </select>
    <input name="submit" type="submit">
    </form>
    Last edited by seco; 08-26-2009 at 01:58 AM.

  • Users who have thanked seco for this post:

    Vacendak (08-26-2009)

  • #3
    New to the CF scene
    Join Date
    Aug 2009
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by seco View Post
    PHP Code:
    <?php
    if(isset($_POST['submit'])){

    $number $_POST['number'];

    echo 
    1000/$number;

    }
    ?>
    Code:
    <form action="" method="post">
    <select name="number">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    </select>
    <input name="submit" type="submit">
    </form>
    Thanks for the perfect prompt response. This has been kicking my butt for 2 days and google just couldn't get done exactly what I wanted to do. You rock.


  •  

    Tags for this Thread

    Posting Permissions

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