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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checkboxes - Changing Values??: Part1

Status
Not open for further replies.

jiggyg

Programmer
Oct 1, 2007
61
US
Hello List! I need to post this in two posts because of it's size, so please bear with me...

I have some questions regarding how to implement a checkbox on my asp page...

I have a checkbox on records on a list indicating if it is a 'Valid Exception' -- if the user checks it, it is hidden on the list, if not, it remains displayed on the list.

After selecting the record(s) that are Valid Exceptions, they click the <Submit> button, and a '1' is stored in the database column indicating it's a Valid Exception.

I also have a 'Show Valid Exceptions' checkbox on the top of the page, that, when clicked, automatically refreshes the page and shows both Valid Exceptions (indicated with a check in the checkbox ) and not Valid Exceptions (those that are not checked).

Here's my dilemma: Let's say the user clicks the 'Valid Exception' checkbox on a record indicating it's OK; then when reviewing the list, realizes it shouldn't be a Valid Exception, that it is indeed wrong, and want to UNCHECK the 'Valid Exception' checkbox ---

How do I do that???


Here's my code in which TWO of the 5 records are marked as "Valid Exceptions":
Code:
<html>
<head>

<link href="../Images/retro/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
			}
		}
                function openEditOccupantWindow(pageURL){
		if (top.occupantWindow){
			top.occupantWindow.close()
			top.occupantWindow = null			
		}
		window.theFrameSet = parent.top
		var wleft=300
		var wtop = 200
		if(window.screen){
			var wtop = window.screenTop
			var wleft = ((window.screen.width / 2) -175)
		}
		top.occupantWindow = window.open(pageURL,'occupantWindow',"width=550,height=480,scrollbars=yes,left="+wleft+",top="+wtop)
		top.occupantWindow.focus()
	}

		function submitForm(){			
			document.forms[0].Submitted.value='true';
			document.forms[0].submit();
		}

	</script>
	<style type="TEXT/CSS"></style>
	
	<script Language="JavaScript">
	function showValid(fld){
		if(fld.checked){location="LocsMultOccs.asp?results=true&CostCenterID=-99&LocationID=-99&showValidExceptions=1"}
		else{location="LocsMultOccs.asp?results=true&CostCenterID=-99&LocationID=-99&showValidExceptions=0"}
		
	}
	</script>
</head>
<body leftmargin="0" topmargin="20" bottommargin="25" rightmargin="0">
<div id="Container">
	<span id="PageHeader">Locations with Multiple Occupants</span>
	<span Class="LoadPage" ID="LoadPage">
				<br><img src="../Images/retro/statusicons/PleaseWait3.gif"><br>Loading page...<br>
	
	</span>
	<script language="javascript">
		showSubs('LoadPage')
	</script>

Part2 -- next post
 
2 things:


1) instead of creating a completely seperate post for part #2, why not just add the 2nd post to this thread, under your first one? That way people don't have to jump between 2 threads to see the whole problem. It would probably be a good idea to copy/paste your 2nd thread as a new post in this thread, and then red flag the other thread so that management can delete it.

2) if I decide to take a look at your issue here and post a suggestion/solution, is it going to fall into the category of ignored advice that my last 2 posts to your questions have been? In case you're wondering, I'm referring specifically to these:

thread216-1424505
thread216-1426182

I don't expect to get a purple star for every post I provide, but it's rude to get free advice from someone and then not even have the courtesy to come back to say "thanks" or let the person know if their solution worked or not. Often times I just ignore questions from posters that abuse the advice I give them, but since you have been more courteous to me in the past I figure I will give you the benefit of the doubt on this one.

-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>[/small]
 
kaht-

1) I didn't even think about that...but, you're right, I should have did that -- and will add it to this.

2) Sorry about not posting back on those last two, I honestly don't know why I didn't do that. I usually DO conciously try to do that, as I spend lots of hours searching the web and forums for solutions to problems, trying to fix them on my own before coming to the forums myself and asking for assitance, and I feel the frustration when reading a post and then not knowing if it worked or not, or if some tweaking had to be done to get it to work by the user. My sincere apologies. I'm thinking I may have figured something out on my own and didn't come back to the forum to follow-up, or else got sidetracked here at work and just forgot about it. Again, I do apologize. This forum has been VERY helpful and cordial in finding solutions with the numerous posts I have created, and I did not, nor would not, purposefully ignore anyones suggestions on here... I did not intentionally ignore your advice, and know from your peers on this board that you are highly regarded by MANY people! My sincere thanks for all of the time and help that you've provided to myself and numerous others here!
 
Code:
<span ID="MainPage">
<br><a href="LocsMultOccs.asp?results=true&type=x&nav=Mozilla%2F4%2E0+
%28compatible%3B+MSIE+7%2E0%3B+Windows+NT+5%2E1%3B+%2ENET+CLR+1%2E1%
2E4322%3B+%2ENET+CLR+2%2E0%2E50727%29&CostCenterID=-99&LocationID=-99&
showValidExceptions=1" target="_blank"><img src="../Images/retro/buttons/exporttoexcel.gif" onmouseover="MM_swapImage('excel',','../Images/retro/buttons/
exporttoexcel_f2.gif',1);" onmouseout="MM_swapImgRestore();" border="0" name="excel" alt="Export to Excel"></a><br><br><br><span id="GreyText">Records returned: 5</span><BR><br><form method="post" action="LocsMultOccs.asp"><input type="hidden" name="Submitted"><input type="hidden" name="CostCenterID" value="-99"><input type="hidden" name="LocationID" value="-99"><table cellpadding="3" cellspacing="3"><tr><td colspan="3"><p>No filters were applied.</p></td>
<td colspan="6" align="right"><input type="checkbox" name="showValidExceptions" value="1" checked onclick="javascript:showValid(this)">&nbsp;&nbsp;Show Valid Exceptions</td></td></tr><tr><th align="center">Valid<br>Exception</th><th align="left">Location</th><th align="left">Business Unit</th><th width="20">&nbsp;</th><th align="center">Last Request<br>Completed Date</th><th align="left">&nbsp;Vacate</th></tr><tr><td colspan="6"><hr></td></tr><tr><td align="center"><input type="checkbox" name="validException" value="104449"  checked></td><td colspan="4"><a href="../Drawings/DrawGetByLocID.asp?LocID=104449&DrawTypeID=-99" target="TopWorkSpace">Century City 14 CEN-14-023 </a></td></tr><tr><td></td><td>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:openEditOccupantWindow('../Occupant/OccDetail.asp?Occid=
105051&edit=true')">Kassab, Lyon</a></td><td>1313 - Sales Planning</td><td width="20">&nbsp;</td><td align="center">11/13/2007</td><td align="center"><input type="checkbox" name="OccAssSelected" value="101679"></td></tr><tr><td></td><td>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:openEditOccupantWindow('../Occupant/OccDetail.asp?Occid=
60311&edit=true')">Visitor's Office</a></td><td>0000 - No Dept/ No budget </td><td width="20">&nbsp;</td><td align="center">9/19/2007</td><td align="center"><input type="checkbox" name="OccAssSelected" value="150068"></td></tr><tr><td colspan="6"><hr></td></tr><tr><td align="center"><input type="checkbox" name="validException" value="104509" ></td><td colspan="4"><a href="../Drawings/DrawGetByLocID.asp?LocID=104509&DrawTypeID=-99" target="TopWorkSpace">Century City 15 CEN-15-033 </a></td></tr><tr><td></td><td>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:openEditOccupantWindow('../Occupant/OccDetail.asp?Occid=
160345&edit=true')">South Conf. Rm.</a></td><td></td><td width="20">&nbsp;</td><td align="center">9/20/2007</td><td align="center"><input type="checkbox" name="OccAssSelected" value="150115"></td></tr><tr><td></td><td>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:openEditOccupantWindow('../Occupant/OccDetail.asp?Occid=
160404&edit=true')">South Conf. Rm.</a></td><td></td><td width="20">&nbsp;</td><td align="center">9/21/2007</td><td align="center"><input type="checkbox" name="OccAssSelected" value="150255"></td></tr><tr><td></td><td>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:openEditOccupantWindow('../Occupant/OccDetail.asp?Occid=
105425&edit=true')">South Conference Roo</a></td><td></td><td width="20">&nbsp;</td><td align="center">9/21/2007</td><td align="center"><input type="checkbox" name="OccAssSelected" value="150256"></td></tr><tr><td colspan="6"><hr></td></tr><tr><td align="center"><input type="checkbox" name="validException" value="157577"  checked></td><td colspan="4"><a href="../Drawings/DrawGetByLocID.asp?LocID=157577&DrawTypeID=-99" target="TopWorkSpace">HP3 08 HP3-8094 </a></td></tr><tr><td></td><td>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:openEditOccupantWindow('../Occupant/OccDetail.asp?Occid=
119561&edit=true')">Bloomfield, Ray</a></td><td>0501 - Controllers Office </td><td width="20">&nbsp;</td><td align="center">7/27/2007</td><td align="center"><input type="checkbox" name="OccAssSelected" value="138098"></td></tr><tr><td></td><td>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:openEditOccupantWindow('../Occupant/OccDetail.asp?Occid=
119561&edit=true')">Bloomfield, Ray</a></td><td>0501 - Controllers Office </td><td width="20">&nbsp;</td><td align="center">7/27/2007</td><td align="center"><input type="checkbox" name="OccAssSelected" value="120138"></td></tr><tr><td colspan="6"><hr></td></tr><tr><td align="center"><input type="checkbox" name="validException" value="157474" ></td><td colspan="4"><a href="../Drawings/DrawGetByLocID.asp?LocID=157474&DrawTypeID=-99" target="TopWorkSpace">HP3 09 HP3-9015 </a></td></tr><tr><td></td><td>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:openEditOccupantWindow('../Occupant/OccDetail.asp?Occid=
156577&edit=true')">File Room</a></td><td>0420 - Supply Chain Planning </td><td width="20">&nbsp;</td><td align="center"></td><td align="center"><input type="checkbox" name="OccAssSelected" value="143229"></td></tr><tr><td></td><td>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:openEditOccupantWindow('../Occupant/OccDetail.asp?Occid=
156581&edit=true')">Storage Room</a></td><td>0603 - IT Enterprise Applications</td><td width="20">&nbsp;</td><td align="center"></td><td align="center"><input type="checkbox" name="OccAssSelected" value="143233"></td></tr><tr><td colspan="6"><hr></td></tr><tr><td align="center"><input type="checkbox" name="validException" value="157478" ></td><td colspan="4"><a href="../Drawings/DrawGetByLocID.asp?LocID=157478&DrawTypeID=-99" target="TopWorkSpace">HP3 09 HP3-9036 </a></td></tr><tr><td></td><td>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:openEditOccupantWindow('../Occupant/OccDetail.asp?Occid=
156578&edit=true')">File Room</a></td><td>0420 - Supply Chain Planning </td><td width="20">&nbsp;</td><td align="center"></td><td align="center"><input type="checkbox" name="OccAssSelected" value="143230"></td></tr><tr><td></td><td>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:openEditOccupantWindow('../Occupant/OccDetail.asp?Occid=
156584&edit=true')">Storage Room</a></td><td>1503 - Strategic Alliances </td><td width="20">&nbsp;</td><td align="center"></td><td align="center"><input type="checkbox" name="OccAssSelected" value="143236"></td></tr><tr><td colspan="6"><hr></td></tr></table></form>    
    </span>

    <script language="javascript">
        showSubs('MainPage')
        showSubs('LoadPage')
    </script>    
</div>

        <div id="SubmitButton">
            <a href="javascript:submitForm();">
            <img onmouseover="MM_swapImage('go',','../Images/retro/buttons/submit_f2.gif',
1);" onmouseout="MM_swapImgRestore();" src="../Images/retro/buttons/submit.gif" border="0" name="go">
            </a>
        </div>
    
</body>
</html>
 
Thanks for the reply - it is appreciated.


Now, with regard to your problem - I'm not sure where javascript fits into the scope of your question.

Looking at the question itself, you've asked:
Here's my dilemma: Let's say the user clicks the 'Valid Exception' checkbox on a record indicating it's OK; then when reviewing the list, realizes it shouldn't be a Valid Exception, that it is indeed wrong, and want to UNCHECK the 'Valid Exception' checkbox ---

How do I do that???

The simple answer is for them to uncheck the box and resubmit the form. I'm not sure what the issue is. Perhaps you could explain with a bit more detail what the actual problem is. If your problem has something to do with getting the value out of the database that indicates the item is a valid exception, then you may want to try posting this to a different forum (like ASP or PHP or whatever server side language you're using). This forum mostly deals with client side javascript issues, and I'm not sure that your question falls into that category.

-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>[/small]
 
It does have something to do with SQL, as I'm setting a value to '1' in the database if the checkbox is checked:

Code:
if (Request("validException")) <> "" then
   set cn = server.CreateObject("ADODB.Connection")
   cn.Open Application("DataConn")
		
   sql = "UPDATE Locations SET LocAllowMultOcc = 1 WHERE LocClientID = " & Session("CurrentCLientID") & " AND LocID IN (" & Request("validException") & " )"
   cn.Execute sql
   cn.Close	
   set cn = nothing
end if

The VALUE for the checkbox, is the LocID...


However, I've brought this issue to several of my colleagues, and the response I've gotten is to try using a hidden field somehow for this, and then, using javascript, check what the value of that field was when the page was first loaded to what it is when the submit button is clicked again, and if it changed, then update the db accordingly. Someone even said something about the hidden field having three possible values: yes if checked, no if not checked, and something to indicate it it changed from when first loaded.

I'm pretty much confused beyond all getout at this point, and am looking for someway to make sense of it...

Thanks,
-jiggyg
 
Well... there's plenty of ways you can do this. Since your colleagues have suggested to use hidden variables to check for a changed state, let's do that. For each checkbox on the page, create a hidden variable to coincide with that checkbox. Any time the checkbox is changed, alter the value of the hidden input. So, when the checkbox is checked, put a 1 in the hidden field and when it is unchecked, change the hidden field back to 0. If the checkbox starts out checked, then you put a 1 in the hidden field when the checkbox is unchecked and 0 when it is checked. This can easily be handled with the onchange event handler attached to the checkbox.

Then, in your asp code flip the value in the database for anything that had been changed on the last submission. So, any value in the database that is 0 gets turned to 1, any value that was 1 turns to 0 for each hidden field with a value of 1 from the previous page. An easy way to do this in sql is to add one and modular divide by 2. Here's an example:

Code:
declare @a tinyint
set @a = 0
select @a

set @a = (@a + 1) % 2
select @a

set @a = (@a + 1) % 2
select @a

This way, you don't have to mess with case statements.

-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>[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top