...

View Full Version : javascript validation for textboxes



alfidino
01-18-2006, 04:07 AM
I have a list item page which displays items. i have a textbox for entering the number quantities for items before adding to cart. however i want to create a textbox (highlighted in red) to enter their choice of colour in words like red, green etc. i just wanna know what is the initial value for this textbox when i want to enter text in textbox cos i cannot put 0. the javaascrript (highlighted in red)is to validate the textbox for entering the number of quantities and i couldnt enter the text for the other textbox when i tested it. I have actually amend the code to x=document.forms[1] but I couldnt add the items to cart when i entered the colour of choice and quantity in the textbox. am i missing something in the javascript code? can anyone help me on this one, thanks.




function check_num(){
x = document.forms[0];
var msg;
var i;
for(i = 1; i < x.elements.length; i++){
if(x.elements[i].type == "text"){
if(isNaN(x.elements[i].value)){
msg = "Please check you key in a number!"
alert(msg);
x.elements[i].focus();
x.elements[i].select();
return false;
} else {
if(x.elements[i - 1].checked == true && parseInt(x.elements[i].value) <= 0){
msg = "Please check the goods u ordered is more than zero!"
alert(msg);
x.elements[i].focus();
x.elements[i].select();
return false;
}
}
}
}
return true;
}
<%
Response.Buffer = True

Dim rs
Dim sqlStr
Dim Logged
Dim Counter
Dim RecCount
Dim i
Dim PageNumber
Dim tablecategory


if(Request.QueryString("page") <> "") then
temp = Request.QueryString("page")
PageNumber = cint(temp)
else
PageNumber = 1
end if
' ***********************************************************************************************
'get the variables
getstrText = Request.QueryString("ThestrText")
getchkText = Request.QueryString("ThechkText")
chkCat = Request.QueryString("TheCategorySelected")
intCatalogID = Request.QueryString("TheCatalogID")
strModel = Request.QueryString("TheModel")
strTextWhere = ""
strCatWhere = ""
' ***********************************************************************************************
Dim iPageSize 'Number of rows in page
Dim iPageCount 'The number of pages we'll get back
Dim strParam 'Passing a parameter
Dim iRecordsShown 'Loop controller for displaying just iPageSize records
iPageSize = 10 'Change this integer to the number of records to display on page

' ***********************************************************************************************
' Build SQL String using the parameters
IF getchkText = "yes" THEN
strTextWhere = "SELECT * FROM Product WHERE (uCase(Product_ID) like '%"&getstrText&"%' "
strTextWhere = strTextWhere & " or uCase(Model) like '%"&getstrText&"%' "
strTextWhere = strTextWhere & " or uCase(Category) like '%"&getstrText&"%' "
strTextWhere = strTextWhere & " or uCase(Description) like '%"_
& getstrText & "%')"
sqlStr = sqlStr & strTextWhere
ELSE
getchkText = "no"
sqlStr = "SELECT * FROM Product WHERE catalogID ='"& intCatalogID &"' AND Model = '" &strModel&"'"
END IF


' Create and open our connection
Dim vPath, pPath, ConString

vPath = "BMP.mdb" 'use this one if database is in root of cart folder
'vPath = "\database\BMP.mdb" 'use this one if database is in root of your website
pPath = Server.MapPath( vPath )

ConString = "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" & pPath & ";" & "JET OLEDB:"
Dim Conn, rsCatalog
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open ConString
Set rsCatalog = Server.CreateObject("ADODB.Recordset")
adOpenStatic = 3
rsCatalog.CursorType = adOpenStatic
rsCatalog.Open sqlStr,Conn
Set rsProdInfo = Server.CreateObject("ADODB.Recordset")
rsProdInfo.PageSize = iPageSize
rsProdInfo.CacheSize = iPageSize
'rsProdInfo.Open sqlStr, Conn, adOpenStatic, adLockReadOnly, adCmdText
adOpenStatic = 3
rsProdInfo.CursorType = adOpenStatic
rsProdInfo.Open sqlStr, Conn

iPageCount = rsProdInfo.PageCount

If iPageCurrent > iPageCount Then
PageNumber = iPageCount
end if
If PageNumber < 1 Then
PageNumber = 1
end if


If iPageCount = 0 Then
Response.Write "No records found!"
Else
'Move to the selected page
rsProdInfo.AbsolutePage = PageNumber


<FORM METHOD="POST">

<INPUT TYPE=HIDDEN NAME="page" value=0>
<TR>
<TD BGCOLOR="#330000" WIDTH="60"><FONT SIZE="-1" COLOR="#FFFF00"><B>Product Code</B></FONT></TD>
<TD BGCOLOR="#330000" WIDTH="120"><font size="-1" color="#FFFF00"><b>Category</b></font></TD>
<TD BGCOLOR="#330000" WIDTH="93"><font size="-1" color="#FFFF00"><b>Brand</b></font></TD>
<TD BGCOLOR="#330000" WIDTH="98"><span class="style6">Colour</span></TD>
<TD BGCOLOR="#330000" WIDTH="98"><font size="-1" color="#FFFF00"><b>Unit</b></font></TD>
<TD BGCOLOR="#330000" WIDTH="216"><FONT SIZE="-1" COLOR="#FFFF00"><B>Description</B></FONT></TD>
<TD BGCOLOR="#330000" WIDTH="71"><font SIZE="-1" COLOR="#FFFF00" FACE="VERDANA"><b>Unit
Price<font SIZE="-2"><br>
(in Singapore dollars)</font></b></font></TD>
<TD BGCOLOR="#330000" WIDTH="99"><FONT SIZE="-1" COLOR="#FFFF00"><B>Order Quantity</B></FONT></TD>
<TR>
<%
RecCount = rsProdInfo.RecordCount

Counter = 0
Do While Counter < iPageSize And Not rsProdInfo.EOF

%>
<TR>
<TD VALIGN=TOP width="60" bgcolor="#FFFF00"><FONT SIZE="-1">
<% = rsProdInfo("Product_ID") %>
</FONT></TD>
<TD VALIGN=TOP width="120" bgcolor="#FFFF00"><FONT SIZE="-1">
<% = rsProdInfo("Category") %>
</FONT></TD>
<TD VALIGN=TOP width="93" bgcolor="#FFFF00"><FONT SIZE="-1">
<% = rsProdInfo("Model") %>
</FONT></TD>
<TD VALIGN=TOP width="98" bgcolor="#FFFF00"><FONT SIZE="-1">
<% = rsProdInfo("Colour") %>
</FONT></TD>
<TD VALIGN=TOP width="98" bgcolor="#FFFF00"><FONT SIZE="-1">
<% = rsProdInfo("Unit") %>
</FONT></TD>
<TD VALIGN=TOP width="216" bgcolor="#FFFF00"><FONT SIZE="-1">
<% = rsProdInfo("Description") %>
</FONT></TD>
<TD VALIGN=TOP width="71" bgcolor="#FFFF00"><FONT SIZE="-1">$<%=formatnumber(rsProdInfo("Unit_Price")) %></TD>
</TR>
<TR>
<TD width="60"></TD>
<TD VALIGN=LEFT width="120">&nbsp;</TD>
<TD VALIGN=LEFT width="93"><font size="-1"><img src="product_images/<%=(rsProdInfo("Product_ID").Value)%>.gif"></font></TD>
<TD VALIGN=LEFT width="98"><input type="text" name=<% = rsProdInfo("Product_ID") %> VALUE="" size=20></TD> <TD VALIGN=LEFT width="98">&nbsp;</TD>
<FONT FACE="VERDANA">
<TD VALIGN=LEFT width="216">&nbsp;</TD>
</FONT>
<TD VALIGN=LEFT width="71">&nbsp;</TD>
<TD VALIGN=LEFT width="99"><FONT SIZE="-1">
<INPUT TYPE="text" NAME=<% = rsProdInfo("Product_ID") %> VALUE=0 size=5>
</FONT><BR>
<INPUT TYPE="checkbox" NAME=Item VALUE="<% = rsProdInfo("Product_ID") %>">
<FONT SIZE="-1">Tick item to add<br>
<INPUT name="Button" TYPE="Button" ONCLICK="submit_addCart('add_cart.asp', 'nothing')" VALUE="Add to cart">
</FONT></TD>
<INPUT TYPE=HIDDEN NAME=<% = rsProdInfo("Product_ID") %>_D VALUE="<% = rsProdInfo("Description") %>">
<INPUT TYPE=HIDDEN NAME=<% = rsProdInfo("Product_ID") %>_Stocks VALUE="<% = rsProdInfo("Stock_In_Hand") %>">
<INPUT TYPE=HIDDEN NAME=<% = rsProdInfo("Product_ID") %>_Price VALUE="<% = rsProdInfo("Unit_Price") %>">
</TR>
<TR>
<TD Colspan=5><!-- Color Bar start -->
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH="100%" BGCOLOR="#000000">
<TR>
<TD><IMG SRC="file:///M|/ALfi/images/spacer.gif" WIDTH=1 HEIGHT=1></TD>
</TR>
</TABLE>
<!-- Color Bar end --> </TD>
</TR>
<%
rsProdInfo.MoveNext
Counter = Counter + 1

Loop
End If
%>
</TABLE>
Page: &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
<%
If RecCount > 10 then
For i=1 to (RecCount / 10) + 1
if(i <> PageNumber) then
if getchkText = "yes" then%>
<A Href="list_item.asp?ThestrText=<%=getstrText%>&ThechkText=yes&page=<% = i %>">
<% = i %>
</A>&nbsp
<%else%>
<A Href="list_item.asp?TheCatalogID=<%=intCatalogID%>&TheModel=3M&ThechkText=no&page=<% = i %>">
<% = i %>
</A>&nbsp
<% end if
else%>
<A>
<% = i %>
&nbsp</A>
<%
end if
next
end if
%>
<BR>
<BR>
<INPUT name="Button" TYPE="Button" ONCLICK="submit_addCart('add_cart.asp', 'nothing')" VALUE="Add to cart">
<INPUT name="Button" TYPE="Button" ONCLICK="submitX('view_cart.asp', 'nothing')" VALUE="View cart">
<INPUT name="Button" TYPE="Button" ONCLICK="reset_all()" VALUE="Reset">
<%
if logged = 1 then
%>
<INPUT name="SUBMIT" TYPE=SUBMIT ONCLICK="submitX('logout.asp', 'nothing')" VALUE='Log Out'>
<%
else %>
<INPUT name="Button" TYPE="Button" ONCLICK="submitX('login.asp', 'nothing')" VALUE="Log In">
<%
end if
%>
</FORM>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum