Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Oct 2003
    Location
    malaysia
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    form loading from database

    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.

  • #2
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:

    Code:
    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 />")
       rsSeats.MoveNext
    loop
    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

    Code:
    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
       rsSeats.MoveNext
    loop

  • #3
    New to the CF scene
    Join Date
    Oct 2003
    Location
    malaysia
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks a lot....
    you save my day.....thank you very much!!

  • #4
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You're welcome


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •