Results 1 to 3 of 3

Thread: Set form value based on user input

  1. #1
    Join Date
    Nov 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Set form value based on user input

    I'm trying to create a custom order page on a hosted shopping cart, therefore I'm working around some limitations. I can use javascript, but I'm not good enough to figure this out.

    The code to place each item in the cart is done with a simple html form, but I need to be able to change the price based on the quantity entered by the end user. Is this possible?

    ie. if user enters qty 1, price is 5.00, qty 2-5, price is 4.50, qty 6 or more, price is 4.00.

    This will need to be repeated many times (30? 50?) on the same page so the code would need to be as short as possible.

    Here's a sample of existing code

    Code:
    <form name="form_1" action="addtocart.aspx" method="post">
    	<input type="hidden" name="ItemNbr" value="123">
    	<input type="hidden" name="product" value="SAMPLE">
    Qty:	<input type="text" name="qty" value="">
    	<input type="submit" name="submit" value="Add To Cart">
    	<input type="hidden" name="price" value="">
    </form>
    Thanks for any and all suggestions!
    Last edited by Katt; 11-29-2010 at 09:51 PM. Reason: removed unnecessary code

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,030
    Thanks
    44
    Thanked 3,211 Times in 3,173 Posts
    Blog Entries
    12

    Default

    This cannot be done reliably nor securely with javascript.

    Extra Information:

    Your users may have javascript disabled, worse - they could perhaps use javascript to make the price whatever they want it to be.

    It should be done in aspx on the addtocart.aspx page or elsewhere. The price per item for each item should be set there manually or retrieved there from a database based upon the item number. The hidden field 'price' on your form should play no role in the matter. The set price from somewhere the user cannot control could be multiplied times the 'qty' value, which should probably be a select drop down list, not a text input. Or if it remains a text input, its value should be validated in aspx as a number and if it passes that, be rounded to the nearest whole number before multiplying times the price. If it doesn't pass as a number, the user should be thrown back and told to enter a valid number, or it should be set to 1. That's why a select is better, you may list only positive whole numbers greater than 0 as options. Using a select element is only a problem if you want to allow more than 10 possible 'qty' numbers.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Nov 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks for the reply. I was looking at javascript because I don't have access to the addtocart.aspx page, or anything server side. But using a select might work - thanks for the idea!

Bookmarks

Posting Permissions

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