Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data Valadation

Status
Not open for further replies.

mpwright

Technical User
Sep 13, 2004
27
GB
Hi there,

Iv recently started a new job & have been asked to ammened a website the person who used to work here had made. It's a small company site with a shopping cart system. There are a few problems that I need to address but ive know idea how as I only have a basic understanding of HTML & java is new to me.

I'll list each problem I have after each one has been sorted to save pasting reams of code.

The first problem I have is the data valadation on the shopping cart page. If a user puts any number of the same item in there shopping cart & then views the shopping cart they are able to ammend the quantities. (Only with a positive number) But if a user has more than one type of item in the shopping cart and tries to update either of the items it throws up the error "invalid quantity" which it shouldnt do. It should update the quantity in the item that it is told to. Now like I said ive got no idea about java script & only a very basic knowledge of html. Could someone please help me with this. Ive pasted the code below.

Kind Regards

<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
<!-- hide JS code
var justValidating = true
function validateForm(f){
var val = f.item.value;
if(/^\d{1,}$/.test(val)){
return true;
}else{
f.item.focus;
alert('Invalid Input for quantity');
return false;
}

}


// end JS hide -->
</SCRIPT>
</head>
<body bgcolor="#FFFFFF" vlink="blue"><form METHOD="get" ACTION="qtyupd.asp" target="_parent" onsubmit="return validateForm(this)">
<div align="center">
<table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%">
<tr valign="top">
<td height="95%">
<div align="center">
<p><font size="5"><b><font face="Arial, Helvetica, sans-serif">Your
Shopping Cart</font></b></font></p>
<p> </p>
</div>
<table width="550" border="1" align="center" bordercolor="#000000" cellspacing="0" height="55">
<tr bgcolor="#333366">
<td height="25">
<table width="100%" border="0" cellspacing="0">
<tr>
<td width="310"><font size="2"><b><font face=Arial color=#FFFFFF> Item
Name</font></b></font></td>
<td width="90">
<div align="center"><font size="2"><b><font face=Arial color=#FFFFFF>Unit
Price</font></b></font></div>
</td>
<td width="32">
<div align="center"><font size="2"><b><font face=Arial color=#FFFFFF>Qty.</font></b></font></div>
</td>
<td width="110">
<div align="center"><font size="2"><b><font face=Arial color=#FFFFFF>Extended
Price</font></b></font></div>
</td>
</tr>
</table>
</td>
</tr>
<tr bgcolor="#FFFFFF">
<td height="25">
<table cellpadding=4 border=0 cellspacing=0 width='550' align="center">

<tr>
<td bgcolor=#FFFFFF width="46%"><font face="Arial, Helvetica, sans-serif" size="2"><a href="reverseget.asp?reverseget=Excelstor ESJ340 40gb 7200rpm ATA100 OEM IDE&start=1">Excelstor ESJ340 40gb 7200rpm ATA100 OEM IDE</a></font></td>
<td bgcolor=#FFFFFF width="11%"> <font face="Arial, Helvetica, sans-serif" size="2"><a href="delitem.asp?item=Excelstor ESJ340 40gb 7200rpm ATA100 OEM IDE" target="_parent"><img src="delete.jpg" height="15" vspace="0" hspace="0" border="0"></a>
</font></td>
<td align=RIGHT bgcolor=#FFFFFF width="17%">
<div align="center"><font face="Arial, Helvetica, sans-serif" size="2">£30.00</font></div>
</td>
<td align=RIGHT bgcolor=#FFFFFF width="6%">
<div align="center"><font face="Arial, Helvetica, sans-serif" size="2">
<input size=2 maxlength=5 name="item" value="1">
</font></div>
</td>
<td align=RIGHT bgcolor=#FFFFFF width="20%">
<div align="center"><font face="Arial, Helvetica, sans-serif" size="2">£30.00</font></div>
</td>
</tr>

<tr>
<td bgcolor=#FFFFFF width="46%"><font face="Arial, Helvetica, sans-serif" size="2"><a href="reverseget.asp?reverseget=Gainward Fx5500 256MB DVI TV-Out &start=1">Gainward Fx5500 256MB DVI TV-Out </a></font></td>
<td bgcolor=#FFFFFF width="11%"> <font face="Arial, Helvetica, sans-serif" size="2"><a href="delitem.asp?item=Gainward Fx5500 256MB DVI TV-Out " target="_parent"><img src="delete.jpg" height="15" vspace="0" hspace="0" border="0"></a>
</font></td>
<td align=RIGHT bgcolor=#FFFFFF width="17%">
<div align="center"><font face="Arial, Helvetica, sans-serif" size="2">£74.79</font></div>
</td>
<td align=RIGHT bgcolor=#FFFFFF width="6%">
<div align="center"><font face="Arial, Helvetica, sans-serif" size="2">
<input size=2 maxlength=5 name="item" value="1">
</font></div>
</td>
<td align=RIGHT bgcolor=#FFFFFF width="20%">
<div align="center"><font face="Arial, Helvetica, sans-serif" size="2">£74.79</font></div>
</td>
</tr>

<!-- html codes and asp codes here to generate the form-->
<tr bgcolor="#CCCCCC">
<td align='LEFT' colspan='3' gcolor='#EEEEEE' height="33" bgcolor="#FFFFFF"><font face="Arial, Helvetica, sans-serif" size="2"><b>Total,
Less Tax and Shipping & Handling:</b></font></td>
<td align='RIGHT' width="6%" height="33">
<div align="center"><b><font face="Arial, Helvetica, sans-serif" size="2" color="#000000">2</font></b></div>
</td>
<td align='RIGHT' width="20%" height="33">
<div align="center"><b><font face="Arial, Helvetica, sans-serif" size="2" color="#000000">£104.79 </font></b></div>
</td>
</tr>
</table>
</td>
</tr>
</table>
<div align="center">
<p> </p>
<table width="400" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<div align="center"><a href="continue.asp?prodid=311" target="_parent"><img src="return.gif" alt="CONTINUE SHOPPING" border="0" width="93" height="35"></a></div>
</td>
<td>
<div align="center">
<input type="IMAGE" src="update.gif" border="0" name="UPDATE QUANTITIES" width="93" height="35">
</div>
</td>
<td>
<div align="center"><a href="emptycart.asp" target="_parent"><img src="clear.gif" alt="EMPTY CART" border="0" width="93" height="35"></a></div>
</td>
<td>
<div align="center"><a href="checkout.asp"><img src="checkout.gif" alt="CHECKOUT" border="0" width="93" height="35"></a></div>
</td>
</tr>
</table>
</div>

</form>





</body></html>

 

Change this:

[tt]if(/^\d{1,}$/.test(val)){[/tt]

to this:

[tt]if('/^\d{1,}$/'.test(val)){[/tt]

*cLFlaVA
----------------------------
Lois: "Peter, you're drunk!"
Peter: "I'm not drunk, I'm just exhausted from stayin' up all night drinking!
 
Hi,

Thanks for your advise, when I change that line I get the error:

Error Type:
Microsoft VBScript runtime (0x800A000D)
Type mismatch: '[string: "1, 2"]'
/asp/qtyupd.asp, line 21

Ive pasted the code to the stated file qtyupd.asp incase you can see anything I need to change in there:

<%

Response.Cookies("modified") = "true"
Response.Expires=0
queries = 0

Set conn = Server.CreateObject("ADODB.Connection")
Conn.Open ("driver={Microsoft Access Driver (*.mdb)};DBQ=" & server.mappath("aspcart5.mdb"))

sql = "SELECT * FROM temporary ORDER BY item;"
set rs = Conn.Execute(sql)

do while not rs.eof
customerid= Request.Cookies("customerid")

If Request.Querystring(rs("item")) <> rs("quantity") and rs("custID") = Request.Cookies("customerid") then

newquantity = Request.QueryString("item")
Response.write(newquantity)

if newquantity = 0 then
sql = "DELETE DISTINCTROW custID FROM temporary WHERE (item='" & rs("item") & "')"
else
sql = "UPDATE DISTINCTROW temporary SET quantity ='" & newquantity & "' WHERE item='" + rs("item") + "' AND custID='" + customerid + "'"
end if

set rs = Conn.Execute(sql)

sql = "SELECT * FROM temporary ORDER BY item;"
set rs = Conn.Execute(sql)

end if

if not rs.eof then rs.movenext
loop

rs.close
set rs = nothing

Response.Redirect("refview.asp")


%>
 
That is a problem with your ASP page, to which the form values are passed. This has now become a question for the ASP forum, since your JavaScript problem has been solved.

*cLFlaVA
----------------------------
Lois: "Peter, you're drunk!"
Peter: "I'm not drunk, I'm just exhausted from stayin' up all night drinking!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top