0

Not exactly sure how to search for this issue I have with VBScript, so please forgive if this is a duplicate.

I have a function that prints pagination on a page that takes 2 parameters, totalpgs and active. My issue is that the active page only applies the style on the link when the variable pg is NOT set. I'm pretty sure this is a logic issue but I've been staring at this for 7 days now.

Here is the function:

'======= Print Pagination links
function print_pagination (totalpgs,active)
    p = "<div class=""row"">"
    p = p & "<div class=""pagination pagination-right"">"
    p = p & "<ul>"
    for x = 1 to totalpgs
        if x = active then
            li = "<li class=""active"">"  '<- Set class for current page
        else
            li = "<li>" '<- else regular link
        end if
        p = p & li & "<a href='?pg="& x &"'>"& x &"</a></li>"
    next 
    p = p & "</ul></div></div>"
    print_pagination = p
end function

Here is the code on the page:

pg = request.querystring("pg")
if pg = "" then
    pg = 1
end if

<%=print_pagination(totalpages,pg) %>

Here is the desired result:

Desired result is graying out the current page.

I want the current <li> to contain a class called active.

This is what's happening:

The active class is never getting applied.

The active class never gets applied to the <li> tag. When the url contains the get variable of pg, no active class is assigned. When it does not, then it's applied to the first link.

1 Answer 1

2

Change your line that does the comparison to this:

    if cstr(x) = cstr(active) then
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.