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 7 of 7
  1. #1
    New Coder
    Join Date
    Apr 2007
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Client side cart need help validating form

    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. Any help would be great.
    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
    Regular Coder
    Join Date
    May 2007
    Posts
    118
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi Jumpkin.. I have never seen action = "javascript: void 0;" in form tag.

    Use rather something like this:

    Code:
    <script>
    function Validate()
    {
     if(document.getElementById('size').selectedIndex < 1)
     {
        alert('Please select a size');
        return;
     }
     document.sizeform.submit();
    }
    </script>
    
    <form method="post" name="sizeform">
      <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="button" value="add to cart" onclick="Validate();">
    </form>
    Forum for webmasters and developers
    http://www.htmlfrenzy.com
    Are you an IT expert? Join our Reward system
    www.htmlfrenzy.com/reward-system.php

  • #3
    New Coder
    Join Date
    Apr 2007
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Small dog,
    Thanks but it didn't work. The pop did show up when nothing was chosen but if a selection was made it did not send the item to the cart.
    Here is the where I got my original code from http://members.aol.com/paypalcart/index1.html

  • #4
    Regular Coder
    Join Date
    May 2007
    Posts
    118
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Jumpink it was an example of course.. you need to use other inputs too in your form.. (and edit JS) that was just demonstration

    So I don't know your code but try this.....

    Code:
    <script>
    function Validate()
    {
     if(document.getElementById('size').selectedIndex < 1)
     {
        alert('Please select a size');
        return;
     }
     SetDesc ('shirt');
     SetCode ('ts00014');
     SetImg ('images/cartimage/shirt.gif');
     SetPcat (2);
     if (ReadForm (document.sizeform, true))
     CallView ();
     ClearAll ();
    
     document.sizeform.submit();
    }
    </script>
    
    <form method="post" name="sizeform">
    $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="button" value="add to cart" onclick="Validate();">
    <br /><br />
    Input <b>Quantity</b> to order - 
      <input type  = "text"
             name  = "qty"
             value = "1"
             size  = "4" />
    <br /><br />
    </form>
    Last edited by smalldog; 05-15-2007 at 03:43 PM.
    Forum for webmasters and developers
    http://www.htmlfrenzy.com
    Are you an IT expert? Join our Reward system
    www.htmlfrenzy.com/reward-system.php

  • #5
    New Coder
    Join Date
    Apr 2007
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Awesome, Awesome, Awesome! Thanks!
    If I added another form for color would that be too complicated or should I just make size and color one form? Also the alert box says [Javascript application] can I customize this?

  • #6
    Regular Coder
    Join Date
    May 2007
    Posts
    118
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Javascript application you mean in the title of alert box? No you can't customize that.. and color.. just try to insert input for color to your "sizeform" <form>.. may be it will work - depends on your server side script part.
    Forum for webmasters and developers
    http://www.htmlfrenzy.com
    Are you an IT expert? Join our Reward system
    www.htmlfrenzy.com/reward-system.php

  • #7
    New Coder
    Join Date
    Apr 2007
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks again. I know you said that the alert box is not customizable but I was wondering if there was a workaround. This site http://www.dustybrand.com/shirts/booty_gray.html
    If you click add to cart without making a selection take notice of the header It says The page at blank blank says: I have seen this on different sites, just wondering if there is an easy way to do this.


  •  

    Posting Permissions

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