View Full Version : form loading from database

10-26-2003, 04:53 PM
Hi there, is me again...

I like to ask that how to disable a multiple checkbox by using the database value when a asp page load.

Example: When you going into a cinema ticket purchase page, the purchased seats will be disable.

10-26-2003, 07:40 PM
OK. Say you have 50 checkboxes (50seats). Named chk1 till chk50. If they are checked, they get checked="checked" and value="5"

You first run a select for all records/ seats. In the db. each seat has a record + each record has a value inside the column seat --> seatnumber. Another value indicates if the seat is taken --> seatstat
You add an order by seatnumber asc to the select

then you can go:

do while rsSeats.EOF = False
response.write("<input id=""chk" & rsSeats.Fields("seatnumber").Value & """ type=""checkbox"" name=""chk" & rsSeats.Fields("seatnumber").Value & """")
if rsSeats.Fields("seatstat").Value = 1 then '1 = taken
response.write(" checked=""checked""")
end if
response.write(" />Seat number " & rsSeats.Fields("seatnumber").Value & "<br />")

if you cant have a record for each seat, and only have records for taken seats, then you need an extra check against an incrementing variable. Like

dim i
i = 1
do while rsSeats.EOF = False
if i = rsSeats.Fields("seatnumber").Value then 'this meanw we have a record with a taken seat
response.write("<input id=""chk" & rsSeats.Fields("seatnumber").Value & """ type=""checkbox"" name==""chk" & rsSeats.Fields("seatnumber").Value & """ checked=""checked"" />")
response.write("Seat number " & rsSeats.Fields("seatnumber").Value & "<br />")

else 'we dont have a taken seat, so we display the checkbox for the next seat unchecked
response.write("<input id=""chk" & i & """ type=""checkbox"" name=""chk" & i & """ />Seat number " & i & "<br />")
end if

10-27-2003, 01:34 AM
thanks a lot....
you save my day.....thank you very much!!

10-27-2003, 06:18 AM
You're welcome :thumbsup: