i like to validate the checkboxes in my form but how should i create an array or a loop? the value for my checkboxes is the name of the product. i have placed it in a loop. the following is my code.
Code:
If Request("Submit")="Submit" then
v = request.form("value")
ex = request.form ("exp")
unit = request.form("unit")
sql1 = "Select * from ABS where item = '" &i& "'AND unit = '" &unit& "'"
Set Rs1 = Server.CreateObject("ADODB.RecordSet")
Rs1.open sql1,conn
If Rs1.eof then
Response.write "No records found,please try again!!!"
Else
if ex = "greater or equals to" then
sqlC = "Select SubID,Item, Grade, GradeName from ABSSubGrade where Grade >= " &v& " AND ABSID = "&rs1("ABSID")&" "
elseif ex = "equals to" then
sqlC = "Select SubID,Item, Grade, GradeName from ABSSubGrade where Grade = " &v& " AND ABSID = "&rs1("ABSID")&" "
else
sqlC = "Select SubID,Item, Grade, GradeName from ABSSubGrade where Grade <= " &v& " AND ABSID = "&rs1("ABSID")&" "
end if
Set RSC = Server.CreateObject("ADODB.RecordSet")
RSC.open sqlC,conn
if RSC.eof then
Response.write "No records found for the given value. Please try again."
Else
if ex = "greater or equals to" then
sql3 = "Select Count(*) as ct from ABSSubGrade where Grade >= " &v& " AND ABSID = "&rs1("ABSID")&""
elseif ex = "equals to" then
sql3 = "Select Count(*) as ct from ABSSubGrade where Grade = " &v& " AND ABSID = "&rs1("ABSID")&""
else
sql3 = "Select Count(*) as ct from ABSSubGrade where Grade <= " &v& " AND ABSID = "&rs1("ABSID")&""
end if
Set RS3 = Server.CreateObject("ADODB.RecordSet")
RS3.open sql3,conn
Dim counter
counter = 0
If not rs3.eof then
counter = RS3("ct")
End if
%>
<br>
<br>
<table width="550" border="1" cellpadding="7" cellspacing="1">
<tr>
<td colspan="2" class="small"><font color="#000000" size="4"><font face="Arial, Helvetica, sans-serif">Modified
ABS</font></font><font color="#000066" size="3" face="Arial, Helvetica, sans-serif"><strong>
<input name="item" type="hidden" id="item" value= "<%=Request("item")%>">
</strong></font></td>
</tr>
<tr>
<td width="213" class="small"><%=i%></td>
<%
rwset=1
ct=1
Do while not rsc.eof
%>
<td width="300" class="small"><font color="#000000">
<div align="center"> <u><strong><%=RSC("GradeName")%></strong></u>
<input name="opt" type="checkbox" id="opt" value="<%=rsc("Item")%>">
</div>
<div align="center">
<table width="101" border="1" cellspacing="0" cellpadding="4">
<tr>
<td width="89" height="46"><div align="center"><%=RSC("item")%>
</div></td>
</tr>
<tr>
<td width="89" height="56"><div align="center"><%=RSC("Grade")%>
</div></td>
</tr>
</table>
</div>
<%
f=rwset mod (ct+1)
if(f=0) then
%>
</font> <font color="#000000"> </font> </td>
</tr>
<%
end if
ct=ct+1
rwset=rwset+1
rsc.movenext
loop
end if
end if
%>
</table>
<br>
<input name="Go" type="submit" id="Go" value="Go">
<br>
<br>
<br>
<%
Response.write "Your search returns "
Response.write cint(counter)
Response.write " records."
'response.write sql3
'response.write sqlC
%>
</strong></font> </div>
Dim f
Dim optValue
For Each f in Request.Form
If len(f) > 2 Then
If Lcase(Left(f, 3)) = "opt" Then '' we found a checkbox
optValue = Right(f, len(f)-3)
'' now u can do something with the value
End If
End If
Next
if ( (document.form1.opt[0].checked != true) &&
(document.form1.opt[1].checked != true) &&
(document.form1.opt[2].checked != true) )
{
alert("Please select at least one grade before submitting the form.");
return false;
}
excuse me, what do u mean by let the ASP generate the Javascript? i do not know the values for the recordset so how should i go about doing it? please enlighten me. thanks a million.
<%
ar = array(1,2,3,4) '' really from a db but this'll work for demo purposes
%>
<script><!--
ar = new Array();
<%
For i = 0 to ubound(ar)
Response.Write "ar[" & i & "]=" & ar(i) & ";" & vbCrLf
Next
%>
// -->
</script>
this could be cleaner, but should serve as an example...i hope
Bookmarks