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

Update via checkbox 3

Status
Not open for further replies.

samflex

IS-IT--Management
Jun 28, 2004
45
US
I created an update code that would update a boolean data type ( access db true/false) data type.

So far, this pair of scripts work:

on edit.asp:

Code:
<tr>
<td>
<b><font color="ffffff">Printed: </font></b></td><td><input type="text" size="60" name="show" value="<%=RS("show")%>"></td>
</tr>

on update.asp:

Code:
Set RS = DataConnection.execute("UPDATE shows SET show= '" & fshow& "' where id =" ID)

This works well.

However, On the edit page, it dispays:
Show = True (or show = False) depending on the situation.

The client has decided that rather than see True or False, they just want to see a checkbox so they if they box is checked meaning True and they want to change the value to False, all they need to do is uncheck the box, click update and the database will be updated.

So far, when I uncheck a checked box and click update, I get an error.

Below is the code I am playing with.
Can I ask for your assistance, please?
Thanks in advance

Code:
	<%
	    IF trim(rs("show")) = "True" then
			Response.Write("<INPUT NAME='fshow' CHECKED TYPE=checkbox VALUE=" & rs("show") & " checked>
		ELSE
			Response.Write("<INPUT NAME='fshow' CHECKED TYPE=checkbox VALUE=" & rs("show") & " >
		END IF
	%>
 
try this instead...
Code:
<%
If LCase(Trim(rs("show"))) = "true" Then
  strChecked = " CHECKED"
Else
  strChecked = ""
End If

Response.Write "<INPUT name='fshow' type='checkbox' value='" & Trim(rs("show")) & "'" & strChecked & ">"
%>

Tony
________________________________________________________________________________
 
hi Tony,
I am still getting the same error I was getting with the code I posted.

Microsoft JET Database Engine (0x80040E14)
Syntax error in UPDATE statement.
 
I forgot to mention that the error occurs on my update code posted above.

With this code:
Code:
<tr>
<td>
<b><font color="ffffff">Printed: </font></b></td><td><input type="text" size="60" name="show" value="<%=RS("show")%>"></td>
</tr>
The update statement works but as I indicated earlier, it works with value = True rather checking and unchecking the checkbox.
 
I think thats because if you unselect a checkbox it doesnt pass through anything, so you may want to do a check on update page.

If LCase(Trim(request("fshow"))) = "true" Then
bShow = "True"
Else
bShow = "False"
End If

- FateFirst
 
oops..and then:
Code:
Set RS = DataConnection.execute("UPDATE shows SET show= '" & bShow & "' where id =" ID)

- FateFirst
 
One more problem:
If your value is originally false then there will be no way to turn it back true :)

Watch:
If you output your checkbox like so: Response.Write "<INPUT name='fshow' type='checkbox' value='" & Trim(rs("show")) & "'" & strChecked & ">"

Then when show is False the checkbox will have the value false. if it is then checked it will pass that False value to the next page, if it isn't checked it won't pass a value to the next page.

On the next page you have:
If LCase(Trim(request("fshow"))) = "true" Then
bShow = "True"
Else
bShow = "False"
End If

Whether or not you check that checkbox, an initial false value cannot be changed to true as both cases will end up in the else portion of your if statement.

The solution is rather simple, just remove the rs("show") from the checkbox value and pass a hard-coded value. if the value is passed then the box was checked, if no value was passed then it wasn't chcked:
Response.Write "<INPUT name='fshow' type='checkbox' value='True'" & strChecked & ">"

Now when the checkbox is checked it sends true, the rest of the time it doens't send anything. Your if statment will now work consistently and all is well :)

01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
Help, the rampaging, spear-waving, rabid network gnomes are after me!
 
very true...didnt notice that.

I assumed (yep..made an ass outta myself) that default value being used is true and only checked would be the changing value...guess I should read peoples posts in more detail.

- FateFirst
 
Great point Tarwn!

I was just coming back to say exactly that even though it works when you uncheck a box, it doesn't work when you attempt to check the box.

No Tarwn, I have tried your solution,
It is still not checking the box when you attempt to update the database by checking a previously unchecked box.

I just love you guys understanding of asp.
 
Tarwns solutions should work.

EDIT PAGE
Code:
<%
If lcase(Trim(RS("show"))) = "true" then
	strChecked = " checked"
Else
	strChecked = ""
End If
%>
<INPUT name="fshow" type="checkbox" value="True"<%=strChecked%>>

UPDATE PAGE
Code:
<%
If LCase(Trim(request("fshow"))) = "true" Then
  bShow = "True"
Else
  bShow = "False"
End If

Set RS = DataConnection.execute("UPDATE shows SET show= '" & bShow & "' where id =" ID)
%>

- FateFirst
 
Thanks to both of you again for all the assistance.

If I use the code with single quotes like this:

'"&bShow&"' I get this error:

Microsoft JET Database Engine (0x80040E07)
Data type mismatch in criteria expression.

If I use it without the single quotes like this:

"&bShow&" it will uncheck the box but will not check it.

As usual, I must be doing something wrong.

I am using exactly you guys code, nothing was changed.
 
more than likely your db environment will store T/F as True False OR 1 and 0 .. try removing the quotes and changing the true to 1 and false to zero and see if you still get errors.

[thumbsup2]DreX
aKa - Robert
 
Double-check in your database that the field is definately set for True/false, not Yes/No or something like that.

-T

01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
Help, the rampaging, spear-waving, rabid network gnomes are after me!
 
It is working now.

Thanks Tarwn as usual for not only coming up with solutions but explaining the problems and possible solutions.
Your style makes asp very easy to understand.

DreXor, thanks for your input.

Most of all, special thanks to FateFirst for coming up with the original code.

 
hrmm

on the edit page can you write:

response.write("<b>" & RS("show") & "</b>")

put it before the code that reads:
Code:
If lcase(Trim(RS("show"))) = "true" then
    strChecked = " checked"
Else
    strChecked = ""
End If

then tell me what you get back

- FateFirst
 
damnit...you guys are too fast...i was just getting to that..hehe

- FateFirst
 
Fate: :)
Challenge a couple DreamWeaver "specialists" to see who can create the more colid app in the least amunt of time, that'll speed you up a bit ;)

Sam: Glad we were able to be of assistance, group hug time :p

Drex: Good call, I think that would work without the change to True/False in the DB, believe I remember that working for true/false, yes/No, etc. ...But I still like my answer better ;)

01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
Help, the rampaging, spear-waving, rabid network gnomes are after me!
 
I know this is off-topic, so sorry, but is anyone else have slight issues with tek-tips being unavailable sometimes.

- FateFirst
 
of course we have, we just dont talk about it *shhh* the tek gods might become angry

[thumbsup2]DreX
aKa - Robert
 
They are still working on the upgrades to the site, so you may see some oddities now and then, especially when they mke changes to major portions of the stylesheets, etc.

-T

01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
Help, the rampaging, spear-waving, rabid network gnomes are after me!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top