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 to the CF scene
    Join Date
    May 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help - check input on submit?

    I have a form with a text box. When the user types into the text box, i need to check what that value is, is it between 0-1000, 1001-5000, or 5001+ and then submit the form.

    How can i do this? I assume i will need a
    Code:
    onsubmit="function here"
    but after that, im confused

    Code:
    <form name="paypalForm" target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
    	<input type='hidden' name='cmd' value='_cart' />
      	<input type="hidden" name="business" value="user@leaderexcelsolutions.com" />
       	<input type="hidden" name="upload" value="1" />
       	<input type="hidden" name="lc" value="US" />
       	<input type="hidden" name="currency_code" value="USD">
       	<input type="hidden" name="item_name_1" value="Tender Touch Towels" />
    Now i need to say, if its below 1000, the following input will have a value of .19, otherwise, .18, etc..

    Code:
    <input type="hidden" name="amount_1" value="0.19">
    
    or if order is 1001-5000
    
    <input type="hidden" name="amount_1" value="0.18">
    
    or if order is 5001-10000
    
    <input type="hidden" name="amount_1" value="0.17">
    Code:
    <input id="fname" class="price_box" value="Type your quantity here"  onkeypress="return numbersonly(this, event)" onfocus="clearText(this)">
    		
    		<input type="submit" class="order_button">

  • #2
    New to the CF scene
    Join Date
    May 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here is what i tried but my onsubmit is not firing

    Code:
    <script>
    function validateIt()
    {
    var quan= document.paypalForm.quantity.value;
    if(quan>=0)
    {
       if(quan<=1000)
       {
          alert("The price is 19 cents");
       }
    } else if(quan>=1001)
    {
       if(quan<=5000)
       {
          alert("The price is 18 cents");
       }
    } else if(quan>=5001)
    {
       if(quan<=10000)
       {
          alert("The price is 17 cents");
       }
    }
    }
    </script>
    Code:
    <form name="paypalForm" action="paypal.com" method="post">
    <input type="text" name="quantity" value="type your quantity" onsubmit="validateIt()" onfocus="clearVal" />

  • #3
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    Code:
    <input type="text" name="quantity" value="type your quantity" onsubmit="validateIt()" onfocus="clearVal" />
    onsubmit attribute is to be given to your form, instead of input element.
    Last edited by abduraooft; 05-14-2009 at 06:23 PM.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #4
    New to the CF scene
    Join Date
    May 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ah thank you!
    Last edited by zang8027; 05-14-2009 at 06:43 PM.

  • #5
    New to the CF scene
    Join Date
    May 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    my next problem is my form is now not submitting. It was fine when i had it alerting but i changed alert() to document.write() and it takes me to a blank page...

    i need it to either add the following to the stage (depending on amount entered)

    <input type="hidden" name="amount_1" value="0.19" />
    <input type="hidden" name="amount_1" value="0.18" />
    <input type="hidden" name="amount_1" value="0.17" />'

    and submit the form with these somewhere in the form

  • #6
    Senior Coder
    Join Date
    Jun 2002
    Posts
    1,404
    Thanks
    2
    Thanked 32 Times in 32 Posts
    It's not a blank page - it's the same one!

    document.write begins a new document when called on a fully-loaded one. There are other ways to prompt a form submitter when needed.

    Was there a particular reason you didn't want to alert them? Fairly typical ...

    Also, you should probably validate the input (numbers, etc.).

  • #7
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,308
    Thanks
    203
    Thanked 2,563 Times in 2,541 Posts
    Code:
    <script type = "text/javascript">
    
    function validateIt() {
    var price = 19;  // default price
    var quan = parseInt(document.paypalForm.quantity.value);
    if ((isNaN(quan)) || (quan == "") || (quan < 1 ) || (quan > 10000)) {
    alert ("You must enter a number between 1 and 10000");
    document.paypalForm.quantity = "";
    document.paypalForm.quantity.focus();
    return false;
    }
    
    if (quan >= 5001) {price = 17}
    else if (quan >= 1000) {price = 18}
    
    alert ("The price is $" + price);
    }
    </script>


  •  

    Posting Permissions

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