Damodar Posted August 10, 2014 Share Posted August 10, 2014 Dear All; Need your help. I am programming students' roll call in ASP with SQL 2008 R2. There are about 100 students. By default option selected is 'Present' using drop down list. I tried to use radio buttons but only one button remains selected so I am using drop-down list ( How to select multiple radio buttons?). After selecting "Present", "Absent","Late" etc, how do I insert all 100( or whatever number) of rows in the SQL table simultaneously? How should I use "for", "loop" or any other method? Please guide. Regards DAMODAR Link to comment Share on other sites More sharing options...
niche Posted August 10, 2014 Share Posted August 10, 2014 (edited) Radio buttons let a user select ONLY ONE of a limited number of choices. http://www.w3schools.com/html/html_forms.asp Then I'd probably use a while loop for the inserting. If you submit some code, we can be more specific. Edited August 10, 2014 by niche Link to comment Share on other sites More sharing options...
Damodar Posted August 10, 2014 Author Share Posted August 10, 2014 Sir; As asked by you I am submitting the code. ======================================================================= <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE> New Document </TITLE> <META NAME="Generator" CONTENT="EditPlus"> <META NAME="Author" CONTENT=""> <META NAME="Keywords" CONTENT=""> <META NAME="Description" CONTENT=""> </HEAD> <!--#include file="session/nosession.asp"--> <!--#INCLUDE FILE="connect/dataconnectivity.asp"--> <BODY onload="dynAnimation()" background="images/saraswati.jpg" bgproperties="fixed"> <IMG SRC="images/sis_logo.jpeg" WIDTH="90" HEIGHT="90" BORDER=0 ALT="INTRANET AKAH"><HR><FONT SIZE="3" COLOR="#330033"><B>DORM DATA ENTRY FORM FOR <FONT SIZE="4" COLOR="#FF0000">ROLL CALL AT BREAKFAST, DINNER AND STUDY HOUR.</FONT></B></FONT><br><FONT SIZE="4" COLOR="#660000"><%response.write(FormatDateTime(date(),vblongdate))%></FONT> <CENTER><A HREF="redirect/loginredirect.asp"><FONT SIZE="3" COLOR="red">Log off</FONT></A> <INPUT TYPE="submit" style="background-color: #C0C0C0; color: #800000; letter-spacing: 5pt; border-style: ridge" value="<" onclick = history.go(-1)></CENTER> <%ses=session("username") if ses="" then Response.redirect"redirect/session_over.asp" end if%> <CENTER><FORM METHOD=POST NAME="rollcall"ACTION="" onsubmit="return validateForm()"> <% rs.Open "SELECT Name_of_Student from AKAH_dorm order by Name_of_Student asc", conn %> <TABLE BORDER="0"> <TR bgcolor="#FFFF00"> <%for each x in rs.Fields%> <%response.write("<th>" & x.name & "</th>")%> <%next%> </tr> <%do until rs.EOF%> <tr> <%for each x in rs.Fields%> <td bgcolor="#CCFFFF"><INPUT TYPE="hidden" NAME="stuname" Value="<%Response.Write(Replace((x.value),"""","'"))%>"><%Response.Write(Replace((x.value),"""","'"))%> </td> <td bgcolor="#CCFFFF"> <SELECT NAME="occasion" value=""> <option selected value="Present" >Present</option> <option value="Absent" >Absent</option> <option value="Fasting">Fasting</option> <option value="Sick">Sick</option> <option value="Out of Campus">Out of Campus</option> </SELECT> </td> <%next rs.MoveNext%> </tr> <%loop rs.close conn.close %> <TR> <TD bgcolor="#CCFFFF">Date</TD> <TD bgcolor="#CCFFFF"> <select name="rdate"> <% for i = 1 to 31 if i = day(now) then Response.Write "<option value="&i&" selected>" & i & "</option>" else Response.Write "<option value="&i&">" & i & "</option>" end if next %> </select> <select name="rmonth"> <% for i = 1 to 12 if i = month(now) then Response.Write "<option value="&i&" selected>" & i & "</option>" else Response.Write "<option value="&i&">" & i & "</option>" end if next %> </select> <select name="ryear"> <% for i = 2013to 2016 if i = year(now) then Response.Write "<option value="&i&" selected>" & i & "</option>" else Response.Write "<option value="&i&">" & i & "</option>" end if next %> </select> </TD> </TR> <TR> <TD bgcolor="#CCFFFF">Roll call for :</TD> <TD bgcolor="#CCFFFF"> <SELECT NAME="occasion" value=""> <option selected value="" >Select</option> <option value="Breakfast" >Breakfast</option> <option value="Dinner">Dinner</option> <option value="Evening Study">Evening Study</option> </SELECT> </TD> </TR> </TR> </TABLE><p> <INPUT TYPE="reset"> <INPUT TYPE="submit"> </FORM></CENTER> <script> function validateForm() { var x=document.forms["rollcall"]["occasion"].value; if (x==null || x=="") { alert("Please select occasion of the roll call.Breakfast, Dinner or Study hour. It's the last row."); return false; } } </script> </BODY> </HTML> =============================== Thanks DAMODAR Link to comment Share on other sites More sharing options...
niche Posted August 10, 2014 Share Posted August 10, 2014 (edited) First, change the drop down to check boxes since you need multiple inputs Edited August 11, 2014 by niche Link to comment Share on other sites More sharing options...
Damodar Posted August 11, 2014 Author Share Posted August 11, 2014 Sir; I changed dropdown to check boxes. I tried below given code. It works but in a strange manner. In my dummy database I have 9 students. Data gets inserted 9 times but in every row of the SQL table I get nine names of the students separated by a comma in first column,nine entries of PRESENT,ABSENT,LATE etc in the second column separated by commas etc. This repeats nine times consuming 9 rows.The code is shown below. Thanks for the valued support. Regards DAMODAR =================================== <% dim i%> <%ses=session("username") if ses="" then Response.redirect"redirect/session_over.asp" end if%> <BODY> <%set rs1= conn1.execute ("select count(*) from rollcall") i = 1 i = i + rs1("") %> <%rs2.open("select count(*)from akah_dorm where Gender = 'GIRL'"),conn2%><hr> <% Dim objExec, counter counter=0 for counter = 0 to rs2(0) response.write("The counter is: "&counter&"<br>")....(This is just for checking.) If rs2(0) <> "" Then strSQL = "" strSQL = strSQL &"INSERT INTO RollCall " strSQL = strSQL &"(Sr_No,Name_of_Student,Status,Occasion,Date) " strSQL = strSQL &"VALUES " strSQL = strSQL &"('"&i&"','"&request.form("stuname")&"','"&request.form("Check")&"','"&request.form("Occasion")&"','"&date()&"')" Set objExec = Conn.Execute(strSQL) End IF next Response.write("Save completed.") Conn.Close() Set objExec = Nothing Set Conn = Nothing %> </BODY> Link to comment Share on other sites More sharing options...
justsomeguy Posted August 11, 2014 Share Posted August 11, 2014 For radio buttons, you give each group of radio buttons the same name, and the user can only select one radio button with the given name. That means that for each student all of their radio buttons need to have the same name, and the radio button groups for each students need to have different names. A common way of handling that is to append something unique to the student, like their ID, to the radio button names. When you're processing the form you look up each student's ID that is being processed and use the ID to get the radio button selection. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now