Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checkbox - Refresh Page?

Status
Not open for further replies.

jiggyg

Programmer
Oct 1, 2007
61
US
Hello List!

I have an ASP page w/ a checkbox on it for showing 'valid exceptions'....problem is, I'm not sure how to refresh the page after the checkbox is checked (if it is checked, show the records w/ valid exceptions, otherwise, don't show them).... There's no buttons on the page, just a report of the records....I'm thinking maybe a hidden submit button and then implementing 'onclick' somehow, but not sure how to do this or if it's the right solution...

Here's the main code that I'm working with:

Code for checkbox:
Code:
<tr>
  <th>
    &nbsp;&nbsp;<br><input type="checkbox" name="showValidExceptions" value="1"<%if request("showValidException") = "YES" then Response.Write " checked" end if%>>Show Valid Exceptions</th>
</tr>

SQL for the select:
Code:
sql = "SELECT * from [MasterDetails].dbo.getInvalidBmkAssignments(" & Session("CurrentClientID") &") "
  if Request("showValidExceptions") = "" then
    sql = sql & "WHERE validException = 'NO' "
  end if
  sql = sql & "UNION "
  sql = sql & "( SELECT * from [MasterDetails].dbo.getUNKNOWNBmkAssignments(" & Session("CurrentClientID") &") "
  if Request("showValideExceptions") = "" then
    sql = sql & "WHERE validException = 'NO')"
  end if

So, I'm missing how to re-submit/refresh the page once the "showValidExceptions" checkbox is checked to show these records as well.....


Any help, information, expertise you can provide would be greatly appreciated!
-jiggyg
 
I suppose the input is properly contained in a form element. In that case, add this onclick handler to it.
[tt]
<tr>
<th>
&nbsp;&nbsp;<br><input type="checkbox" name="showValidExceptions" value="1"<%if request("showValidException") = "YES" then Response.Write " checked" end if%>
[blue]onclick="if(this.checked) {this.form.action=''; this.form.submit();}"[/blue]>Show Valid Exceptions</th>
</tr>
[/tt]
 
Thanks for the reply, tsuji.

Actually, no, there is no form on the page...


<%@ language="VBScript" %>
<html>
<head>
<!--#include file="../Includes/PageGuard.inc"-->
<!--#include file="../Includes/ErrorHandler.inc"-->
<link href="../<%= session("imageDirectory")%>/style.css" type="text/css" rel="stylesheet">
<script language="javascript">
function showSubs(Myparent){
if(document.getElementById){
thisMenu = document.getElementById(Myparent).style
if(thisMenu.display == "block"){
thisMenu.display = "none"
}
else{
thisMenu.display = "block"
}
return false
}
else{
alert("not working")
return true
}
}
</script>
</head>

<body topmargin="20" leftmargin="20" rightmargin="0" bottommargin="0">
<span ID="PageHeader">Manage Invalid Benchmark Assignments</span>
<span Class="LoadPage" ID="LoadPage">
<%Randomize
intRandom = Rnd()
intRandom = ((intRandom * 10) mod 4) + 1
%> <img src="../<%=session("ImageDirectory")%>/StatusIcons/PleaseWait<%=intRandom%>.gif">
</span>
<script language="javascript">
showSubs('LoadPage')
</script>
<%Response.Flush%>

<% '*** Put any major page processing here - the above code will show the please wait icon %>
<span ID="MainPage">

CHECKBOX CODE
<tr>
<th>
&nbsp;&nbsp;<br><input type="checkbox" name="showValidExceptions" value="1">Show Valid Exceptions</th>
</tr>

<%
'*** Put the main contents of the page here ***
if Request("msg") <> "" then
Response.Write "<p><font color=""red"">" & Request("msg") & "</p>"
end if

--order by code
select case UCase(Request("OrderBy"))
case "LOC6"
strOrderBy = "L6"
case "LOC5"
strOrderBy = "L5"
case else
strOrderBy = ""
end select

SQL
sql = "SELECT * from [MasterDetails].dbo.getInvalidBmkAssignments(" & Session("CurrentClientID") &") "
if Request("showValidExceptions") = "" then
sql = sql & "WHERE validException = 'NO' "
end if
sql = sql & "UNION "
sql = sql & "( SELECT * from [MasterDetails].dbo.getUNKNOWNBmkAssignments(" & Session("CurrentClientID") &") "
if Request("showValideExceptions") = "" then
sql = sql & "WHERE validException = 'NO')"
end if

if cstr(strOrderBy) <> "" then
sql = sql & " ORDER BY " & strOrderBy
else
sql = sql & " ORDER BY [L6], [L5], [L4], [L3], [L2]"
end if

--create connection and get results
set rs = server.CreateObject("ADODB.Recordset")
rs.Open sql, Application("DataConn")
if not rs.EOF and not rs.BOF then
aInfo = rs.GetRows()
rs.Close
set rs = nothing

--write results to table
Response.Write "<table cellpadding=""3"" cellspacing=""3"">"
Response.Write "<tr>"
Response.Write "<th ID=""HeaderLinks"" align=""left""><a href=""InvalidBenchmarkAssignments.asp?OrderBy=LOC6"">Loc 6</a></th>"
Response.Write "<th ID=""HeaderLinks"" align=""left""><a href=""InvalidBenchmarkAssignments.asp?OrderBy=LOC5"">Loc 5</a></th>"
Response.Write "<th ID=""HeaderLinks"" align=""left""><a href=""InvalidBenchmarkAssignments.asp?OrderBy=VALIDEXCP"">Valid Exception</a></th>"
Response.Write "</tr>"

for i = 0 to UBound(aInfo, 2)
if i mod 2 = 0 then
Response.Write "<tr>"
else
Response.Write "<tr bgcolor=""#E6EEFF"">"
end if
Response.Write "<td>" & aInfo(3,i) & "</td>" 'Loc6
Response.Write "<td>" & aInfo(4,i) & "</td>" 'Loc5
Response.Write "<td>" & aInfo(15,i) & "</td>" 'Exception
Response.Write "</tr>"
next
Response.Write "</table>"
else
Response.Write "<br><big>&nbsp;&nbsp;No invalid benchmark assignments."
end if
%>
</span>

<script language="javascript">
showSubs('MainPage')
showSubs('LoadPage')
</script>
</body>
</html>
 
Actually, no, there is no form on the page...

Then, how are you passing information from the submitted page?

Also, one helpful thing about posting code in the javascript forum - always paste the derived code for the page, not your server side code. 99% of the time the backend asp and sql stuff has nothing to do with the javascript solution - since javascript is run client side. It makes it much easier to debug if we don't have to wade thru the useless info. Right click on your page and click "view source" or "view page source" to get the derived code - this is the only thing the browser sees, and consequently the only thing that the javascript sees.

Now, back to the problem. You'll need to add a form to the page to send information during submission unless you are manually building the querystring and using something similar document.location to switch the page. As far as how to detect if a checkbox was checked when a page has been submitted, here's a small test:
Code:
<%
   if request.form("chk").count > 0 then
      Response.Write "checkbox was checked during submission<br />"
   end if
%>
<form method="post">
   <input type="checkbox" value="1" name="chk" />
   <input type="submit" value="click me" />
</form>



-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson
[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B> bites again.[/small]
 
By the way, I use JScript for my ASP coding instead of VBScript, so there may be a bug or 2 in my code above since I know little to nothing about VBScript.... [sad]

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson
[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B> bites again.[/small]
 
I knew there was something I liked about you, kaht. :)# I use JScript for my ASP coding, too.

Lee
 
word!
headbang.gif


-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson
[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B> bites again.[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top