Saveing value from checkbox

While changing a name of a category, I wan't people to be able to choose to publish or unpublish the category by ticking a checkbox.



The category name is saved like this:
if e = 0 then
sql = "Update Categories set catName = '"& catName &"' where catID = "& catID &";"
cn.execute(sql)
 
I need to save value from checkbox named ActiveCheck also, but I'm not sure how to put it in the code above.
 
If the checkbox is checked the value is True else it's False.

Open in new window

GDB08Asked:
Who is Participating?
 
Wayne BarronConnect With a Mentor Author, Web DeveloperCommented:
Let me know if this is what you want?
http://ee.cffcs.com/Q_24408583/Q_24408583.asp
code
http://ee.cffcs.com/Q_24408583/Q_24408583.zip

Files included:
Q_24408583.asp = List all entries (Click on ID's to edit their properties)
get.asp = Edit Entry (By ID)
post.asp = Update entry in the database.
Q_24408583.mdb = sample db
Q_24408583.zip - Archive.

Good Luck
Let me know???
Carrzkiss
0
 
GDB08Author Commented:
The name of the checkbox is ActiveCheck and the field name is Active
<input type="checkbox" name="ActiveCheck"<% If rs("Active") Then Response.Write "checked=""checked""" %> />
0
 
Wayne BarronAuthor, Web DeveloperCommented:
if e = 0 then
sql = "Update Categories set catName = '"& catName &"',[Active] =  " & (request.Form("ActiveCheck") = "on") where catID = "& catID &";"
cn.execute(sql)

Good Luck
Carrzkiss
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
Wayne BarronAuthor, Web DeveloperCommented:
sorry

if e = 0 then
sql = "Update Categories set catName = '"& catName &"',[Active] =  " & (request.Form("ActiveCheck") = "on") & " where catID = "& catID &";"
cn.execute(sql)      

Carrzkiss
0
 
GDB08Author Commented:
Hi Carrzkiss and thanks for tour time.

This is not working so far.  I have a list of 10 records and 4 of them have the checkbox checked.
Before this changing above, when á pressed the edit button behind the selected record, the checkbox stayed checked and I could change the name.
Now, the checkbox resets when I press the edit button and if I make it checked again, it wan't be saved to the database but the name is still saved.

I have a hidden field:
<input type="hidden" name="ActiveCheck" value="<%=rs("Active")%>"/>
and of I run <%=rs("Active")%> I get True on 4 records and False on others.

I tried to replace "on" with "True" but that didn't work either.
[Active] =  " & (request.Form("ActiveCheck") = "True") &
0
 
Wayne BarronAuthor, Web DeveloperCommented:
is your checkbox's Dynamic? Or Static?
If they are Dynamic, then you will need to use another method for this.
If it is Static, then this method should work.

Can you put together a demo project and send it over so I can take a look at what you are
Doing?

Carrzkiss
0
 
GDB08Author Commented:
The checkbox's are dynamic, the records are displayed like this:
<%
      set cn = server.CreateObject("adodb.connection")
      cn.open strCon

      set rs = cn.execute("select * from Categories order by catID")
      do while not rs.eof
%>
      <tr>
      <td  width="20%"  bgcolor="#Ffffff">
      <font color="#111111"><b> &nbsp; <%=rs("catName")%></b></font>
      </td>
      <td  width="10%"  bgcolor="#Ffffff">
      <font color="#111111"><b> &nbsp; <input type="checkbox" name="ActiveCheck"<% If rs("Active") Then Response.Write "checked=""checked""" %> /></b></font>
      </td>

What I get displayed is the the catname, then the checkbox and finally an edit button.
Everything is working fine except the checkbox field I just added.  It shows the value that I added directly in the database but I cant change it.

Part 2

Then it's the part when pressing the edit button to edit the selected record.  Then the category name is displayed above the list on the same page in a editable text field and maybe my mistake is that the checkbox has also to be displayed there, but not only the whole list below.

                  if request.form("action") = "edit_category" then
                  response.Write("<table width=""96%"" cellpadding=""0"" cellspacing=""1"" border=""0"" bgcolor=""#111111"">")
                  response.Write("<tr><td  width=""60%"" style=""padding:6px"" bgcolor=""#d6ddd3"" >")

                  response.Write("<form method=""post"" action=""Categories.asp"" name=""addNew"">      " & vbnewline )
                  response.Write("<b>Breyta flokk : </b> <input type=""text"" name=""catName"" size=""45"" value="""& request.Form("catName") &"""/>" & vbnewline )
                  response.Write("<input type=""hidden"" value="""& catID &""" name=""catID""/> &nbsp;" & vbnewline )
                  response.Write("<input type=""submit"" value=""Edit"" name=""func""/> &nbsp;" & vbnewline )
                  response.Write("<input type=""submit"" value=""Delete"" name=""func""/> &nbsp;" & vbnewline )
                  response.Write("</form>")
                  response.Write("</td></tr></table>")
                  end if

Part 3

The edit function looks like this:

                  if request.form("func") = "Edit" then
                  if IsValidString(request.form("catName")) then
                  catName = trim(replace(request.form("catName"), "'", "''"))
                  else
                  response.Write("Invalid character !<br/>")
                  e = e + 1
                  end if
                  if len(catName) > 99 or len(catName) < 5 then
                        response.Write(" !<br/>")
                  e = e + 1
                  end if

                  if e = 0 then
                  sql = "Update Categories set catName = '"& catName &"' where catID = "& catID &";"
                  cn.execute(sql)
                  response.Write("<p align=""center"">The category has been saved<br/>")
                  end if
                  end if


0
 
Wayne BarronAuthor, Web DeveloperCommented:
are you doing in sort of Loop?
1
2
3
======
Or are you just doing 1 record at a time? As in your code here>

<tr>
      <td  width="20%"  bgcolor="#Ffffff">
      <font color="#111111"><b> &nbsp; <%=rs("catName")%></b></font>
      </td>
      <td  width="10%"  bgcolor="#Ffffff">
      <font color="#111111"><b> &nbsp; <input type="checkbox" name="ActiveCheck"<% If rs("Active") Then Response.Write "checked=""checked""" %> /></b></font>
      </td>
0
 
GDB08Author Commented:
Just one record at a time as in the code.
0
 
GDB08Author Commented:
and it repeats:

      rs.movenext
      loop
      rs.close
      set rs = nothing
      cn.close
      set cn = nothing
0
 
Wayne BarronAuthor, Web DeveloperCommented:
ok.
Can you please package up a test script for me with a sample of your database.
ZIP it up and send it over please?
You will have to change the .asp files to .txt to upload to EE.

It is going to be best for me to see your script in action.
As you just said:

>>Just one record at a time as in the code.

And then your other post you state
>>and it repeats:

I need to see it running please.

Carrzkiss
0
 
GDB08Author Commented:
It's a part of a big system so it's not easy to just pick this only part out of it.  I think I just have to cancel it for now.
0
 
Wayne BarronAuthor, Web DeveloperCommented:
Help me to understand what it is that you are doing here?

OK
#1: Are you editing 1 record at a time?
If you are only editing 1 record at a time, then let me know?

#2: If you are editing multiple records, then I need to know that.

I am assuming that it is #1 as your code above shows only display of 1 record.
BUT, where is the Loop coming in at?

I will make up a demo for you, and you can let me know if it will work for you. OK?

Give me a couple minutes will not take long.

Carrzkiss
0
 
GDB08Author Commented:
Thanks a lot Carrzkiss for your time and great support :-)

I'm only editing one record at time.  
I get a list of 10 records, just like when listing news articles and that´s were the loop come in, to display all the records.

Then I press the edit button behind the record I want to edit, say record number 4 (catID=4) and that record goes in edit mode.  
The catname is displayed in a new editable text field above the 10 records that were displayed before and there is a Edit button to save the name when it has been changed.  (if request.form("func") = "Edit" then....)

I somehow have to get the checkbox also in this edit mode so the value can be changed.

0
 
Wayne BarronAuthor, Web DeveloperCommented:
OK.
This will do it for you.

Carrzkiss
0
 
GDB08Author Commented:
Thanks a lot for your great support :-)
0
 
Wayne BarronAuthor, Web DeveloperCommented:
:) It is an awesome feeling to be able to assist people, after all.
I have received a lot of knowledge from EE and other places around the Internet.
Awesome LOVE Knowledge.

Carrzkiss

Author Comments:
Thanks a lot for your great support :-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.