Can anybody point out why this javascript validation is not working.
I need to validate the page from accepting negative numbers:-
0 is ok
-1 to - whatever should give an alert.
Thanks
Dave.
<%@LANGUAGE="VBSCRIPT"%>
<%option explicit%>
<html>
<head>
<title></title>
<SCRIPT language="JavaScript">
<!--Hide JS Validation Code-->
var justValidating = true
function validateForm (form)
{
if (!validateQty(form.Qty.val
ue)) //Quantity validate
{
form.Qty.focus()
return false
}
return true
}
//<!--Negative Quantity-->
function validateQty(Qty) //Verify Negative Quantity script
{
if (isBlank(Qty))
{
alert("Please insert the quantity you require.")
return false
}
if (document.QuantityChange.Q
ty.value <0)
{
alert("Your have entered a negative number.")
return false
}
else
return true
}
// end JS hide -->
</script>
</head>
<!--Cart.asp page-->
<link href="stylesheet2.css" rel="stylesheet" type="text/css">
<link href="stylesheet1.css" rel="stylesheet" type="text/css">
<link href="stylesheet3.css" rel="stylesheet" type="text/css">
<body>
<!--#include file="inc/header.asp"-->
<!--#include file= "dbconn.asp"-->
<!--#include file= "adovbs.inc" -->
<!--Cart.asp page, holds and diplays details of quantity, items, and prices of
purchases, with delete
and quantity modification proceedures.-->
<%
Response.write"<table width='779'><tr> <td width='779' height='246' align='center'
valign='top'>"
Dim myRS, mySQL, subtotal, total, artsearch
Set myRS = Server.CreateObject("ADODB
.Recordset
")
mySQL ="SELECT tbl_cartitems.CartItemID, tbl_cartitems.CartID,
tbl_cartitems.artistname, tbl_cartitems.cdtitle, tbl_cartitems.cdcost,
tbl_cartitems.qty, tbl_Carts.Cust_ID FROM tbl_Carts INNER JOIN tbl_cartitems ON
tbl_Carts.CartID = tbl_cartitems.CartID WHERE (((tbl_cartitems.CartID)="
& CartID &
"));"
myRS.Open mySQL, myConn
If myRS.EOF Then
'Response redirect if cart is empty.
Response.Redirect "Empty.asp?cartid=" & Cartid & " "
else
'Cart table header layout.
Response.write"<table width='82%' border='1' align='center' cellpadding='2'
cellspacing='0' bordercolor='#FFFFFF' valign='top'>"&_
"<tr bordercolor='#FFFFFF'>"&_
"<td width='79' height='25' valign='top'><span
class='innertablewhite'>Qu
antity:</s
pan></td>"
&_
"<td width='72' valign='top'><span
class='innertablewhite'>Re
move:</spa
n></td>"&_
"<td width='260' valign='top'><span
class='innertablewhite'>It
em:</span>
</td>"&_
"<td width='15%'><span class='innertablewhite'>Pr
ice:</span
></td>"&_
"<td width='17%'><span class='innertablewhite'>Su
bTotal:</s
pan></td><
/tr>"
While Not myRS.EOF
'Cart table details layout.
Response.write"<tr bordercolor='#FFFFFF'>"&_
"<td align='center' valign='top'><form action='qtymod.asp'
method='get'name='Quantity
Change' id='QuantityChange'onsubmi
t='return
validateForm(this)'>" &_
"<input type='hidden' name='CartItemID' value='" &_
myRS("CartItemID") & "'>" &_
"<input type='hidden' name='CartID' value='" & CartID & "'>" &_
"<input type='text' name='Qty' id='Qty'size='2' value='" &_
myRS("Qty") & "'><input type='submit' value='Chg.'>" &_
"</form></td>"&_
"<td align='center'><form action='delete.asp?CartID=
" &_
CartID & "&CartItemID=" & myRS("CartItemID")&"' method='post'><input
type='submit' name='Submit' value='Delete.'><Input type ='hidden' name='CartID'
value='"&CartID&"'> </form></td>"&_
"<td valign='top'><span class='record2'>"
&myRS("artistname")&"<br>"
&myRS("cdt
itle")&"</
span></td>
"&_
"<td><span class='record2'>£"&FormatN
umber(myRS
("cdcost")
)&"</span>
</td>"
Subtotal=myRS("cdcost") * myRS("Qty")
response.write"<td align='center'><span
class='record2'>£"&FormatN
umber(Subt
otal)&"</s
pan></td><
/tr>"
Total = Total + Subtotal
myRS.MoveNext
Wend
End If 'End of recordset loop.
'Displays items in cart.
Artsearch =request.querystring ("Artistname")
Response.write"<tr bordercolor='#FFFFFF'>"&_
"<td height='25' colspan='4' align='right' class='innertable'>Total
Cost:</td>"&_
"<td align='center'><span
class='record2'>£"&FormatN
umber(Tota
l)&"</span
></td></tr
>"&_
"<tr><td colspan='5' align='center' valign='middle'><form action='store.asp'
method='get'>"&_
"<Input type ='hidden' name='CartID' value='"&CartID&"'><input type='submit'
name='Submit' value='Back To Store.'></form> "&_
"<form action='artsearch.asp' method='get'>"&_
"<Input type ='hidden' name='CartID' value='"&CartID&"'>"&_
"<Input type ='hidden' name='Artsearch' value='"&artsearch&"'>"&_
"<input type='submit' name='Submit' value='Back To Search Results.'></form>"&_
"<form action='order.asp?CartID="
& CartID & "' method='post'>"&_
"<input type='hidden' name='Total' value='" & FormatNumber(Total) & "'><input
type='submit' name='Submit' value='Checkout.'></form>"
&_
"</td></tr>"&_
"</table>"&_
"</td>"&_
"</tr>"&_
"</table>"
%>
<!--#include file="inc/footer.asp"-->
</body>
</html>
Start Free Trial