Maintain state of checkbox While Paging

Posted on 2004-10-26
Last Modified: 2008-01-09
I need to maintain a checkbox's "checked" status while paging back and forth with a querystring on the same page. I think this will require vb or javascript to work.

Here is my code:

Dim i
      For i=1 To pagesize

      r = n Mod 2
      if r <> 0 then
         rowColor = "#FFF0AF"
         rowColor = "#F0FFCF"
      end if

Dim vAuthCode,vNPANXX,vAddDate,vActiveDate,vDeactiveDate
Dim vRouting,vCarrier,vAuthType

vAuthCode = RS("auth_code")

vA_NPA = left(RS("auth_code"),3)
vA_NXX = mid(RS("auth_code"),4,3)
vA_Num = right(RS("auth_code"),4)
<tr bgcolor="<%=rowcolor%>">
<td align=center nowrap><font class=content><%=vA_NPA%>-<%=vA_NXX%>-<%=vA_Num%></font></td>
<td align=center nowrap><input type=checkbox name="ordernum" id="ordernum" value="<%=vAuthCode%>"></td>
 End If
<tr><td colspan=99 align=right bgcolor="#BBBBBB">
<input type=hidden name="action" id="action" value="bulkOrder"><input style="width: 200px;" class=button type=submit name=submit1 id=submit1 value="RESERVE SELECTED NUMBERS" onClick="return confirmSubmit()"></td></tr></table></td></tr></table>
<blockquote><font class=content><b>Jump to Page: </b>
if not isEmpty(Request.QueryString("sort")) then
vSort="sort=" & column
ElseIf not isEmpty(Request.QueryString("sortd")) then
vSort="sortd=" & column
End If

Dim x, lb, ub
      For x=1 To numpages
        lb = (x-1) * pagesize + 1
        ub = x * pagesize
        If ub > numrecs Then ub = numrecs
        If x <> mypage Then
          Response.Write("<a class=content href=number_inventory.asp?page=" & x & "&select2="& vFilter2 &"&recs=" & pagesize & "&"& vSort &">" & lb & "-" & ub & "</A>")
          Response.Write(lb & "-" & ub)
        End If
        If x <> numpages Then Response.Write(" | ")

End If

      Set RS = Nothing
      Set objConn = Nothing
Question by:xeroflux
    LVL 15

    Expert Comment

    input type=checkbox name="ordernum" id="ordernum" value="<%=vAuthCode%>" <% if( Request.QueryString( "ordernum" ) <> "" ) then Response.Write( "checked" ) end if%> >
    LVL 7

    Expert Comment

    Building on justinbillig's comment.

    Lets say you have this variable that you want to carry over to another page..

    CurTime = now()

    You 1st need to send it to the next page.  The only way this can be done is with a Form or Querystring depending on your needs. I have done it with both.

    Response.redirect("nextpage.asp?CurTime=" & CurTime)

    Then on the next page you can get the CurTime value using this:

    CurTime = Request.QueryString("CurTime")

    Author Comment

    The pagination runs on the same page. The only time the form would be submitted is after you've checked your checkboxes from the various pages.

    The paging querystring could be used to trigger a javascript that detects what has been checked on each page and holds them in a cookie or array.

    Neither of your answers really solves the problem.
    LVL 15

    Accepted Solution


    I am not sure but this is just an idea. I think the only way to go over your problem is using cookies cause it can be set using client side scripting like javascript. You can use the checkbox as a way in setting the cookies. When you check one of the checkbox you will set the cookies using client side scripting

    below is a link that might help...

    Now when you pass the page on the pages you can read the cookies using serverside so that you can preserved the checkbox value

    below is a link that might be helpful in reading cookies server side.

    now you can something like this in your page

    <input type=checkbox name="ordernum" id="ordernum" value="<%=vAuthCode%>" <%=setSelect(vAuthCode)%>>

    Now your function would be something like this...

    Function setSelect(a)
    for each x in Request.Cookies
    if trim(a) = trim(Request.Cookies(x))then
    setSelect = "checked"
    exit for
    end if
    end function

    This will compare the the dynamic values with cookie collection everytime the page is loaded put checked if data is the same... that way will preserv the checkboxes...

    This is just an idea out of my brain... I am not sure if this will work but you can give it a try....


    HAppy programming...

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Learn The Basics of Ethical Hacking & Pen Testing

    Computer and network security is one of the fastest growing and most essential industries in technology, meaning companies will pay big bucks for ethical hackers. This is the perfect course to leap into this lucrative career, learning how to use ethical hacking to reveal ...

    I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
    Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    884 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now