CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 2007
    Posts
    19

    Defaulting a Value of a Text Input Field

    I've got the following script. It allows a user to input a quantity, then the new price is updated. But there seems to be a code error (in that is doesn't update for the new price).

    Can anyone see where the error might be?

    Code:
    <?php
    if(isset($_POST["quantity"]))
    	$quantity = settype($_POST["quantity"], "integer");
    else
    	$quantity = 1;
    
    $item_price = 10.99;
    printf("%d x item = $%.2f",
    	$quantity, $quantity * $item_price);
    ?>
    <FORM ACTION="buy.php" METHOD=POST>
    Update quantity:
    <INPUT NAME="quantity" SIZE=2
    value =<?php echo $quantity;?>">
    <INPUT TYPE=SUBMIT VALUE="Change quantity and re-calculate price">
    </FORM>
    Last edited by PeejAvery; May 28th, 2008 at 07:59 AM. Reason: Added code tags.

  2. #2
    Join Date
    May 2008
    Location
    New Jersey
    Posts
    4

    Re: Defaulting a Value of a Text Input Field

    settype() is being used incorrectly. It should be:

    Code:
    if(isset($_POST['quantity'])) {
        $quantity = $_POST['quantity'];
        if(!settype($quantity, 'integer'))
            $quantity = 1;
    } else {
        $quantity = 1;
    }
    Chaos
    Lost Souls MUD: text-based RPG
    MUDseek: MUD search

  3. #3
    Join Date
    May 2007
    Posts
    19

    Re: Defaulting a Value of a Text Input Field

    Thanks. That now works!

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured