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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with check boxes

Status
Not open for further replies.

GG4676

Programmer
Jul 23, 2001
4
US
Hello I have a VBScript function to fill a table with records and fields from a database. The problem I am having is that I can’t find a way to fill my table with check boxes. I want the name of the check box to equal the name of the corresponding record out of the database. Any help would be appreciated. Thank you.

The code I have looks like this:

<%
Function RecToTable (objRS)
Dim strT
Dim fldF
strT = &quot;<TABLE BORDER=1><TR ALIGN=CENTER>&quot;

For Each fldF In objRS.Fields
strT = strT & &quot;<TD>&quot; & fldF.Name & &quot;</TD>&quot;
Next
strT = strT & &quot;</TR>&quot;

While Not objRS.EOF
strT = strT & &quot;<TR ALIGN=CENTER>&quot;
For Each fldF In objRS.Fields
strT = strT & &quot;<TD>&quot; & fldF.Value & &quot;</TD>&quot;
Next
strT = strT & &quot;</TR>&quot;
objRS.MoveNext
Wend
strT = strT & &quot;</TABLE>&quot;
RecToTable = strT
End Function
%>
 
For Each fldF In objRS.Fields
strT = strT & &quot;<TD><input type=checkbox name=&quot; &_
fldF.Name &_
&quot;>&quot; & fldF.Value & &quot;</TD>&quot;
Next br
Gerard
 
Thank you that worked great. I have three records going in the table so it puts a check box on every record. Is there a way to put just the check box on all the records in the first column only? Thank you.
 
dim lFirst = true
While Not objRS.EOF
strT = strT & &quot;<TR ALIGN=CENTER>&quot;

For Each fldF In objRS.Fields
strT = strT & &quot;<TD>&quot;
if lFirst then
strT = strT & &quot;<input type=checkbox name=&quot; &_
fldF.Name & &quot;>&quot;
lFirst = false
end if
strT = strT & fldF.Value & &quot;</TD>&quot;
Next

strT = strT & &quot;</TR>&quot;
lFirst = true
objRS.MoveNext
Wend
br
Gerard
 
That worked perfect. Thank you fo all your help.
 
Does anyone know how to validate check boxes using VBscript? I have 10 check boxes and I need to make sure that the user has checked at least one of them.

Thanks
 
Here is...
Code:
<HTML>
<HEAD>
<META NAME=&quot;GENERATOR&quot; Content=&quot;Microsoft Visual Studio 6.0&quot;>
<TITLE></TITLE>
</HEAD>
<BODY>
<INPUT type=&quot;checkbox&quot; id=checkbox1 name=checkbox1>
<INPUT type=&quot;checkbox&quot; id=checkbox1 name=checkbox1>
<INPUT type=&quot;checkbox&quot; id=checkbox1 name=checkbox1>
<br>
<script language=&quot;vbscript&quot;>
Sub doCheck
 valid = false
	for each val in document.all.item(&quot;checkbox1&quot;)
		valid=valid or val.checked
	next
 if valid then 
	msgbox &quot;Validated!&quot;
 else
    msgbox &quot;Not Valid!&quot;
 end if
End sub
</script>
<INPUT type=&quot;button&quot; value=&quot;Go&quot; onclick=&quot;doCheck&quot;>
</BODY>
</HTML>
________
George, M
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top