File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Javascript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Javascript" Watch "Javascript" New topic
Author

Javascript

arpit singla
Ranch Hand

Joined: Jun 18, 2001
Posts: 66
I have a shopping cart showing the list of books, each book has a textfield corresponding to it, where user can fill in the quantity of books. I have javascript to check if the user has filled in the correct quantity. it works fine when 1 book is added to cart. But gives error when multiple books are added to the cart.
Javascript :
<script>
function Check()
{
n = document.forms["addtocart"].quantity.value;

if(n.length == 0)
{
alert("Please enter some quantity");
document.forms["addtocart"].quantity.focus();
return;
}
// more code
}
</script>
i get following error in Intenet Explorer separate window with yellow sign at the side :
Problems with this web page might prevent it from displayed properly or functioning properly.
n.length might not be an object.
My Update button calls Check() function:
<input type="Submit" name="update" value="Update" onClick="Check()">
Quantity textfield is:
<input type="int" name="quantity" size="2" maxlength="2" value="<%= Integer.parseInt((String)request.getAttribute("quantity"))%>">
i am getting this error due to javascript. if somebody could figure out the problem. Please let me know.
thanks
srikanth bukkapatnam
Greenhorn

Joined: Jul 31, 2001
Posts: 7
Try this :
var n = document.forms["addtocart"].quantity.value;
arpit singla
Ranch Hand

Joined: Jun 18, 2001
Posts: 66
srikanth
i get all the alerts if i add 1 book to the cart but doesn't work if add more than 1. this happens whether i put :
n = document.forms["addtocart"].quantity.value;
or
var n = document.forms["addtocart"].quantity.value;

thanks for your help
arpit
Aman Rustogi
Greenhorn

Joined: May 11, 2001
Posts: 22
Arpit i feel the error is due to naming conflict.
Do all the text boxes where u enter the quantity have the same name? If that's the case, then the ERROR is bound to happen. U can avoid this by assigning different name's to each edit control and also test the object reference returned using 'eval()' in ur javascript function.
I hope this will resolve ur problem with my understanding.
cheers
Aman
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Javascript