This topic is locked
[SOLVED]

 Create checkbox on list page to filter list

8/8/2008 2:10:17 PM
ASPRunnerPro General questions
L
lyngaaskhan author

ASPRunnerPro 5.2 (build 423)
I would like to create a checkbox on my list page that will call an advanced search url.

To be specific, the record items will be either "Open" or "Closed". I have the search url for closed items and for open items.

I would like to have the list page show only open items. When the checkbox is selected, closed items would be displayed.
I believe that I need to insert an asp snippet with something like:

"<select onChange=""java script: document.location='search_url.asp'"">"
But I do not want to use a list, just a checkbox.
any ideas?
Thanks

L
lyngaaskhan author 8/8/2008

Okay, I'm getting closer.
This code creates the check box which loads the search page when checked. (search_url.asp?querystrings is used in place of the extremely long search url to make the example readable)
str = "<Input type=checkbox onClick=""java script: document.location='search_url.asp?querystrings'"">"

str = str & "Closed items"
Response.write str
Next I need to figure out how to track the checked state of the box so that it remains checked when the search page loads.

After that, I need to have the default list page load if the box is unchecked.
Clearly I need to write a funtion rather than simply redirecting on click....

L
lyngaaskhan author 8/9/2008

For those interested, here is my solution. No doubt there is a better way to accomplish the same thing, but it works. I am writing a lengthy explanation so that this might help you with your implementation.
On the list page, insert an asp code snippet where you want to see the checkbox. An explanation follows.
'begin asp code snippet
%>

<script language="jscript">
function checkclosed()

{

var sPath = window.location.pathname;

var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
if (document.getElementById("closed").checked)

{

location.href=sPage+'?a=advsearch&type=and&asearchfield%5B%5D=ClosedDate&not_ClosedDate=on&asearchopt_ClosedDate=Empty&bolcheckbox=true'

}

else

{

location.href=sPage+'?a=search&value=1&SearchFor=&SearchOption=Empty&SearchField=ClosedDate'

}

}
</script>
<%

if request.querystring("bolcheckbox") = "true" then

bolCheckBox="checked"

Else

bolCheckBox=""

end if
response.write "<INPUT type=""checkbox"" id=""closed"" name=""closed"" " & bolCheckBox & " onClick=""checkclosed()"">"

response.write "Show closed requests"
'
end asp code snippet
The %> tag closes the vbscript section so that a jscript section can be inserted. Note that the vbscript section is opened again after the jscript end tag (</script).
The checkclosed function first gets the current page name so that the redirect to the search page is relative to the current page. I have multiple list pages with different filters, so I wanted a more generic function.
Next, the the function checks for the checkbox id 'checked' property. If the property is set to true, the box is checked, which causes the page to be reloaded with the specified search parameters in the query string. In this case, search for records where the "ClosedDate" field is NOT empty. Note the addition of the query string "bolCheckBox=true", which I will get to in a moment.
If the checkbox checked property is not set to true (the else statement), the page is loaded witht he query string specifying records where the "closedDate: field IS empty.
Now, the script checks the request string for the value of "bolCheckBox". The purpose of this is to set the checkbox property to checked or unchecked. When the page reloads, the checkbox default would be unchecked, but if the page is loaded as result of checking the box, I want the box to remain checked. Conversely, if I have just unchecked the box, the querysting will not have the "bolCheckBox" value, so the checkbox will now show as unchecked.
The final two lines are simple the checkbox and the text to appear next to it.
I've also added a Before SQL query event for this page:
'begin before sql query code
if request.querystring("bolcheckbox") = "true" then

strSQL = AddWhere(strSQL, "[ClosedDate]IS NOT null")

Else

strSQL = AddWhere(strSQL, "[ClosedDate]IS null")

end if
'
end before sql query code
This ensures that the page loads with the correct record set on initial visit and when opening the page from another link.
There you have it, I hope this is of use to someone.

S
sleighbor 11/5/2008

Hi Lyngaaskhan,
I just wanted to say thank you for posting this solution. I was looking for this same functionality and your code worked perfectly.
thank you.

Kevin