473,621 Members | 2,745 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

validating quantity

Hello I have a function like this

function checkquantitiy( quantitiy){

if(quantitiy.va lue != parseInt(quanti tiy.value)) {
alert(quantitiy .value+" sorry not integer quantitiy");
}

} //End of function

This check if quantitiy is integer. In the form I have following

<input name="buyquanti tiy" type="hidden" id="buyquantiti y" value="<?php echo
$buyquantitiy; ?>" size="1" maxlength="3">
<input name="quantitiy " type="text" id="quantitiy" value="1" size="1"
maxlength="3" onchange="javas cript:return checkquantitiy( this);">

The problem is when i will calculate if quantitiy/buyquantitiy is an
integer. The reason is that some products can only be seld as 4 items, and
if you press 3 wou should get a message that says
"Sorry a quantity of 3 are not aviable because there are 4 items in
package". Can transfer 2 varibales into the function? Or have anyone any
suggestion how to solve this.

Terje
Jul 23 '05 #1
3 2331
"Terje" <te***@cyberfac tory.no> wrote in message
news:nm******** ************@ne ws000.worldonli ne.dk...
Hello I have a function like this

function checkquantitiy( quantitiy){

if(quantitiy.va lue != parseInt(quanti tiy.value)) {
alert(quantitiy .value+" sorry not integer quantitiy");
}

} //End of function

This check if quantitiy is integer. In the form I have following

<input name="buyquanti tiy" type="hidden" id="buyquantiti y" value="<?php echo $buyquantitiy; ?>" size="1" maxlength="3">
<input name="quantitiy " type="text" id="quantitiy" value="1" size="1"
maxlength="3" onchange="javas cript:return checkquantitiy( this);">

The problem is when i will calculate if quantitiy/buyquantitiy is an
integer. The reason is that some products can only be seld as 4 items, and
if you press 3 wou should get a message that says
"Sorry a quantity of 3 are not aviable because there are 4 items in
package". Can transfer 2 varibales into the function? Or have anyone any
suggestion how to solve this.

Terje


Is "quantitiy" in Norwegian for the English "quantity"?

Will this help?

A second parameter is passed which, if non-zero, will be used to validate
the minimum "quantitiy" .

<html>
<head>
<title>quantity .htm</title>
<script type="text/javascript">
function checkQty(qty,mi n){
if (qty.value != parseInt(qty.va lue,10)) {
alert("Quantiti y not numeric");
} else if (min > 0 && qty.value < min) {
alert("Quantiti y below minimum of " + min);
}
}
</script>
</head>
<body>
<form action="" method="post" name="form1">
<input type="text" name="quantitiy " id="quantitiy"
value="1" size="1" maxlength="3"
onchange="check Qty(this,4);">
</form>
</body>
</html>
If "1" is a desired value then it will not be validated as the "onchange() "
event does not fire.
Jul 23 '05 #2
McKirahan wrote:
[...]
if (qty.value != parseInt(qty.va lue,10)) {
alert("Quantiti y not numeric");


0.5 will fail the test, but it is certainly a numeric value. The
original error message was better:

alert(quantitiy .value+" sorry not integer quantitiy");

But why not:

alert("Quantity must be a whole number of "
+ min + " or more.");

Then the same error message can be used for both cases.

--
Fred
Jul 23 '05 #3
JRS: In article <nm************ ********@news00 0.worldonline.d k>, dated
Tue, 25 Jan 2005 19:38:23, seen in news:comp.lang. javascript, Terje
<te***@cyberfac tory.no> posted :
Hello I have a function like this

function checkquantitiy( quantitiy){

if(quantitiy.va lue != parseInt(quanti tiy.value)) {
alert(quantitiy .value+" sorry not integer quantitiy");
}

} //End of function

This check if quantitiy is integer. In the form I have following

<input name="buyquanti tiy" type="hidden" id="buyquantiti y" value="<?php echo
$buyquantiti y; ?>" size="1" maxlength="3">
<input name="quantitiy " type="text" id="quantitiy" value="1" size="1"
maxlength="3 " onchange="javas cript:return checkquantitiy( this);">

The problem is when i will calculate if quantitiy/buyquantitiy is an
integer. The reason is that some products can only be seld as 4 items, and
if you press 3 wou should get a message that says
"Sorry a quantity of 3 are not aviable because there are 4 items in
package". Can transfer 2 varibales into the function? Or have anyone any
suggestion how to solve this.

See <URL:http://www.merlyn.demo n.co.uk/js-valid.htm>.

The best way to validate such starts with a RegExp;

input = quantity.value
OK = /^\d+$/.test(input) // all digits
OK = /^[1-9]\d*$/.test(input) // all digits, not starting 0

If OK, input = +input will safely convert to string.

With a RegExp /^\d{1,3}$/ you can allow at most 3 digits, if that's
useful.

OK = /^[1-9]\d*$/.test(input) && input%4==0 // & divisible by 4

But, to transfer two parameters into a function
function Add(X, Y) { return X+Y } // for numbers
function Add(X, Y) { return +X + +Y } // for numbers/strings

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
5787
by: Alex Bink | last post by:
Hi, I have a validating event on a textbox in which I want to prevent the user to leave the textbox without entering the right data. Only if he clicks on another specific control he is allowed to leave the textbox without entering the right information. Is there a way to determine which other control was clicked in the validating event of the textbox? Thanks
2
1616
by: Gary Vidal | last post by:
I have a shopping cart webpage that shows a product and the Quantity they would like to order: When you click the link I want to take the quantity that they entered in the textbox and post that to the next page. But it keeps the original quantity I added to the viewstate. Where can i code this to post the correct quantity. Here is the code-behind I use. Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)...
0
1549
by: Joe | last post by:
Hi For a while now I have been finding postings of problems with the validating event not firing on controls properly. I too had this problem. The event would fire when clicking on another control which had it's causes validation property set to true however if I tabbed on to this control the event wouldn't fire. So after playing around with my code I figured out how to get it to work. I am not sure what the reason behind it is but it...
1
1864
by: Brendan | last post by:
I am trying to validate the data in all of the text and combo boxes. The text box validation seems to be working fine, but I am having the hardest time with the combo box validation. I am not sure why, but I keep recieving the error message: "An unhandled exception of type 'System.NullReferenceException' occurred in homework6.exe Additional information: Object reference not set to an instance of an object."
2
2119
by: Chris Dunaway | last post by:
I have a form with a textbox and numerous panels, buttons and other controls. I have handled the textbox Validating and Validated events. The textbox will hold a filename. In the validating event, I check that the string in the textbox is a file that exists or whether or not the string is blank and display a message box in either case. I also call e.Cancel so that the value will be corrected. However, certain buttons on the form...
0
2432
by: Gary Shell | last post by:
I am experiencing some strange behavior between a UserControl's validating event and a treeview control. Initially, I thought it was related to an issue in the Knowledgebase article 810852 (http://support.microsoft.com/kb/810852), but then I realized that the hotfix mentioned was in .Net v1.1, which I am using. I took the sample from that article and recreated the situation I see in my application. (Code included below.) If you run the...
8
2040
by: Martin | last post by:
I hope not, but, I think the answer to this question is "it can't be done". Northwind sample database. Orders form. Go to a new record. Select a customer in "Bill To:" Don't enter any products whatsoever. Now click or page up/down away from this new record. You just created a new order without a single item having been ordered. Not something a user should be able to do.
5
2557
by: HandersonVA | last post by:
should I set to "0" as a default value on a quantity and a price field or set to "null"? if a user enter nothing on the quantity or price field on a web browser, should I treat it as null or "0"? I am so confused about this concept. please advise me. thank you.
14
2080
by: kang jia | last post by:
hi i am doing shopping online, i will let user choose their prodcut in the first page and then when they click" order" button, they will be redirected to do_addcart.php. i will insert their orders into "orders" table and retrieve them back and ask user to select their respective quantity and size. i have used Javascript validation: the code is below: <script language="JavaScript"> <!-- function validate_form ( ) {
0
8213
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8653
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8597
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8306
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8457
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7127
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6101
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5554
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
1763
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.