Clientside validtion >= or just >

# Thread: Clientside validtion >= or just >

1. Senior Member
Join Date
Dec 1969
Posts
286

## Clientside validtion >= or just >

hello all,<BR><BR>can somebody please point me in the right direction just want to check form field value qty is equal to or greater then the order min in this case 2.00<BR><BR>Thanks all<BR><BR>&#060;script type="text/javascript" language="javascript"&#062;<BR>function CheckForm() <BR>{<BR>if (document.forms.form3.qty.value &#060; "2.00") {<BR>alert("Qty is not equal to or more than the order minimun of 2.00 !");<BR>document.forms.form3.qty.focus();<BR>retur n false;<BR>}<BR>}<BR>&#060;/script&#062;

2. Senior Member
Join Date
Dec 1969
Posts
5,955

## A bit of mathematics for you...

...then:<BR><BR>if (A &#062; B) is equal to if (!(A &#060;= B))<BR>if (A &#060;= B) is equal to if (!(A &#062; B))<BR>if (A == B) is equal to if (!(A != B))<BR><BR>Oliver.

3. Senior Member
Join Date
Dec 1969
Posts
16,931

## RE: Clientside validtion >= or just >

While what you&#039;re doing will work, you&#039;re comparing strings. Technically "11.25" is less than "2.00".<BR><BR>You want:<BR>if(parseInt(document.forms.form3.qty.valu e) &#060; 2) {<BR><BR>Craig.

4. Senior Member
Join Date
Dec 1969
Posts
286

## thats great thanks ALL <eom>

.

5. Senior Member
Join Date
Dec 1969
Posts
286

## LOL I Lied Still cant work it out :¬(

I am using asp to loop through an rs and making multiple forms and client side check (well trying to)<BR><BR>here&#039;s on set as it apears in view source<BR>(the validation seems not to do anything at all)<BR><BR>;;;;;;;; Code ;;;;;;;;;;;;;;;<BR><BR>&#060;script type="text/javascript" language="javascript"&#062;<BR>function CheckForm_1() <BR>{<BR>if (parseInt(document.forms.form_1.qty.value) &#060; "2.00") {<BR>alert("Qty is not equal to or more than the order minimun of 2.00 !");<BR>document.forms.form_1.qty.focus();<BR>retu rn false;<BR>}<BR>if (document.forms.form_1.qty.value == "0") {<BR>alert("Qty is not equal to or more than the order minimun of 2.00 !");<BR>document.forms.form_1.qty.focus();<BR>retu rn false;<BR>}<BR>}<BR>&#060;/script&#062;<BR>&#060;form name="form_1" action="addtocart.asp" method="post" OnSubmit="return CheckForm_1()"&#062;<BR>&#060;input type="text" size="3" name="prodqty" value="0"&#062;&#060;input type="hidden" name="prodPrice" value="3.00"&#062;<BR>&#060;input type="hidden" name="prodID" value="1"&#062;&#060;input type="Submit" value="Add To Cart" Name="Submit" class="default"&#062;<BR>&#060;/form&#062;

6. God
Senior Member
Join Date
Dec 1969
Posts
18,177

## Wrong field name.

Your JavaScript refers to "qty", but your HTML refers to "prodqty".<BR><BR>Pick one.<BR><BR>Some simple debugging would have helped:<BR>alert(document.forms.form_1); // what do you see? "object" or "undefined"?<BR>alert(document.forms.form_1.qt y); // what do you see? "object" or "undefined"?<BR><BR>If you see "object", you know you got it right. If you see "undefined", then you got it wrong.<BR><BR>And, you&#039;re trying to compare an integer against a string. Again - get your types right.

7. Senior Member
Join Date
Dec 1969
Posts
96,118

## Also...

You used parseInt to convert the text form of the quantity to an integer...AND THEN COMPARED IT TO A STRING!!! <BR><BR>ILLEGAL.<BR><BR>Compare it to a NUMBER!<BR><BR>Also, you should *CHECK* for a number!<BR><BR>&#060;script type="text/javascript" language="javascript"&#062;<BR><BR>function CheckForm_1() <BR>{<BR> var fld = document.form_1.prodqty;<BR> var qty = parseInt(fld.value);<BR> if ( isNaN(qty) )<BR> {<BR> alert("You did not enter a valid number for the quantity!";<BR> fld.value = "0";<BR> return false;<BR> }<BR> if ( qty &#060; 2 )<BR> {<BR> alert("Minimum order quantity is 2.
Enter a value 2 or greater.");<BR> fld.value = "0";<BR> return false;<BR> }<BR> return true; // do NOT forget this!<BR>}<BR><BR>&#060;/script&#062;

#### Posting Permissions

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