View Full Version : Help - check input on submit?

05-14-2009, 05:49 PM
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
onsubmit="function here" but after that, im confused

<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..

<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">

<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">

05-14-2009, 06:18 PM
Here is what i tried but my onsubmit is not firing

function validateIt()
var quan= document.paypalForm.quantity.value;
alert("The price is 19 cents");
} else if(quan>=1001)
alert("The price is 18 cents");
} else if(quan>=5001)
alert("The price is 17 cents");

<form name="paypalForm" action="paypal.com" method="post">
<input type="text" name="quantity" value="type your quantity" onsubmit="validateIt()" onfocus="clearVal" />

05-14-2009, 06:21 PM
<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.

05-14-2009, 06:40 PM
Ah thank you!

05-14-2009, 06:50 PM
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

05-14-2009, 07:02 PM
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.).

Philip M
05-14-2009, 08:26 PM
<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 = "";
return false;

if (quan >= 5001) {price = 17}
else if (quan >= 1000) {price = 18}

alert ("The price is $" + price);

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum