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!

How To Check Checkbox When Page Reloads 3

Status
Not open for further replies.

jiggyg

Programmer
Oct 1, 2007
61
US
Hello List!

I have an issue I could use some expertise on....

I have a page that allows the user to click a checkbox to distinguish if the entry is a valid exception --> if yes, saves a '1' to the database....

Now, when I reload the page, I want to have the checkbox checked if the user had previously checked it, just now sure how to do it.....


Here's my code so far:

Code:
<tr>
  <th align="left" ID="HeaderLinks">
    &nbsp;&nbsp;<input type="checkbox" name="validException" value="1">Valid Exception</th>
<%
   if request("validException") = "YES" then
     Response.Write "CHECKED"
   else
     Response.Write "NO"
   end if
%>
</tr>

The IF stmt is working correctly -- if it's checked (Or "YES" is passed into the page), it's going into the IF stmt, if it's NOT checked, it's going into the ELSE stmt...

Now, I just need to know how to check the box when the page is reloaded if it's in the IF stmt....

Thanks in advance for your time and help!!
-jiggyg
 
Using your code:
Code:
<tr>
  <th align="left" ID="HeaderLinks">
    &nbsp;&nbsp;<input type="checkbox" name="validException" value="1"<%
   if request("validException") = "YES" then
     Response.Write " checked=""checked"" "
   end if
%>>Valid Exception</th>
</tr>

Lee
 
Code:
<tr>
  <th align="left" ID="HeaderLinks">
    &nbsp;&nbsp;<input type="checkbox" name="validException" value="1" [!]<%if request("validException") = "YES" then Response.Write "checked=""checked""" end if%>[/!]>Valid Exception</th>
</tr>

or, if you're using JScript with ASP (like I always do), I'd use a ternary operator:
Code:
<tr>
  <th align="left" ID="HeaderLinks">
    &nbsp;&nbsp;<input type="checkbox" name="validException" value="1" [!]<%=((request("validException") == "YES") ? 'checked="checked"' : '')%>[/!]>Valid Exception</th>
</tr>

-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]
 
Thanks for the replies!!

Got it working; ended up using kaht's solution to clean it up a bit.

THANKS again!
-jiggyg
 
jiggyg, you can award multiple stars in any given thread - you aren't restricted to 1 person. Lee gave the exact same solution and was 2 minutes faster getting it to you. He deserves a star as much as me (if not more than me).

Lee, I threw a star your way just in case jiggyg doesn't come back to extend the favor.

In any case, I'm glad you got it workin [thumbsup2]

-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]
 
Thanks, kaht. You and I are often real close in providing the same solution to questions asked here. :)#

Lee
 
You and I are often real close in providing the same solution to questions asked here

You know what they say about great minds [smile]


you guys are j4606ing the forum
[lol]

-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