PDA

View Full Version : ASP in Vbscript....form valition comparing datavalues and form values using VBscript


Thimo
10-24-2002, 03:51 AM
another question here,

how come i cannot compare like <%rs("ItemQuantity")%> with the variable i created in the script tag, i would like to use the function like MsgBox to display like "Requested Quantity too much"

like for my Addshoppingcart.asp, i manged to display all the items and the quantites available, so at this page i allow them to key in their requested quantity

form name="form1" method="post" action="AddToCart.asp" >
<table border="1" align="center">
<tr>
<th height="25">Item Code</th>
<th>ItemName</th>
<th>Quantity</th>
<th>Price</th>
<th>Request Quantity</th>
</tr>
<%Do While Not rs.EOF %>
<tr align=center>
<td><%=rs("ItemCode")%></td>
<td align=left><%=rs("ItemName")%></td>
<td><%=rs("Quantity")%> </td>
<td><%=FormatCurrency(rs("Price"))%> </td><td><input name="RQty" type="text" size="3" maxlength="3" ></td>
<tr>
<%rs.MoveNext%>
<%loop%>
</table>

the form actions to AddTocart.asp, i can't seem to use Javascript or Vbscript functions for like form validation....please advice...

like compare quantity.
<%
'setting recordset and SQL statement

If Request("Qty") > rs("ItemQuantity")
Msgbox "Quantity not enough!!"

%>

i cannto do this right?...

BigDaddy
10-24-2002, 04:53 AM
Did you get an error message? If so, what?

I'd say, heck, try it. You'll find out soon enough if it doesn't work.

Thimo
10-24-2002, 06:49 AM
Permission denied MsgBox

its seems that inside the script tag cannot insert any ASP Codes...

Roy Sinclair
10-24-2002, 02:55 PM
You are making a fundamental mistake in what you are trying to accomplish. Specifically you are trying to have code which is running on your server interact in real time with the user who is sitting at another computer (maybe thousands of miles distant).

What you need to do is think in terms of pages going back forth to the user's browser. If there are input errors when the user fills out the form you need to return the form to the user with the appropriate error message as a part of the returned form (it's alway correct to put the user's input back into the form fields so they don't have to retype everything).

Once you've got that working properly, then you can add client side checking with javascript too. Never count on client side code to catch user errors because the user could have the client side code disabled but it is good to have client side checking whenever possible since it can save the user a round trip to the server.

whammy
10-25-2002, 02:14 AM
What Roy said... it seems you don't understand the difference between server-side and client-side scripting. Does anyone have any really good links explaining this?

If so I will make a sticky thread out of it.

I may also consider a thread explaining how to pass server-side variables to client-side scripts, since I use that kind of thing all the time, but any input is appreciated.

Thimo
10-25-2002, 07:39 AM
What you need to do is think in terms of pages going back forth to the user's browser. If there are input errors when the user fills out the form you need to return the form to the user with the appropriate error message as a part of the returned form (it's alway correct to put the user's input back into the form fields so they don't have to retype everything).

i guess i understand abit.....

so for my case, i juz redirect the user to the same page displaying some error messages?, for example

when the user click the item he wants on the ViewItems.asp, maybe ItemID 10, 11. then the Addshoppingcart.asp will display all the items info and the Quantity, beside the table. i added a textbox for the user to enter its quantity. how do i alert the user that he had entered an quantity that is higher than the stock available, lets say that i dun display the quantity info.

when the user click the submit button, redirect him back to this page again. display a error message using response.write?

please advice..

whammy
10-26-2002, 04:48 AM
Yeah, that's corrrect.

Basically you want to make sure that people can't put in the wrong data. That's all validation is.

So if they put in isn't a number, or it is too small, then display an error on the page...

A decent example of basic validation:

http://www.solidscripts.com/email.txt