Results 1 to 4 of 4

Thread: Form validation script for client side cart

  1. #1
    Join Date
    May 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Form validation script for client side cart

    Required field(s) validation

    http://www.dynamicdrive.com/dynamici...uiredcheck.htm

    I have a client side shopping cart. The problem is with my form. If someone does not choose a size it will still add to cart. I want a window to pop up saying please choose a size if none has been chosen. I have entered some code to try to validate the form but it is not performing correctly. Not sure where or how to use the Required field(s) validation script.
    Thanks
    Code:
    <form action   = "javascript: void 0;"
          method   = "post"
    	  onsubmit = "SetDesc ('shirt');
                               if(document.getElementById('size').selectedIndex < 1) {
                               window.event ? window.event.returnValue = false :e.preventDefault = true;alert('Please select a size');
      }
                      SetCode ('ts00014');
                      SetImg ('images/cartimage/shirt.gif');
                      SetPcat (2);
                      if (ReadForm (this, true))
                        CallView ();
                      ClearAll ();
                      return false;">
    
      $17.95 - 
      <input type="hidden" name="initer" value=" @0" />
      <select id="size" size="1" name="size">
     
        <option selected value="Select a size">Select a size</option>
        <option value = "Small @17.95">Small</option>
        <option value = "Medium @17.95">Medium</option>
        <option value = "Large @17.95">Large</option>
    	<option value = "X-Large @17.95">XL</option>
    	<option value = "2XL @19.95">2X ($2)</option>
      </select>
      <input type    = "submit"
             name    = "submit"
             value   = "add to cart" />
    
    <br /><br />
    Input <b>Quantity</b> to order - 
      <input type  = "text"
             name  = "qty"
             value = "1"
             size  = "4" />
    <br /><br />
    </p>
    </form>

  2. #2
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    try ?
    Code:
    if(document.getElementById('size').value == "Select a size") {

  3. #3
    Join Date
    May 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I tried but it was unsuccessful.

  4. #4
    Join Date
    May 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Here is the where I got my original code fromhttp://members.aol.com/paypalcart/index1.html

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
  •