Link to home
Start Free TrialLog in
Avatar of GDB08
GDB08

asked on

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

Avatar of GDB08
GDB08

ASKER

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""" %> />
Avatar of Wayne Barron
if e = 0 then
sql = "Update Categories set catName = '"& catName &"',[Active] =  " & (request.Form("ActiveCheck") = "on") where catID = "& catID &";"
cn.execute(sql)

Good Luck
Carrzkiss
sorry

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

Carrzkiss
Avatar of GDB08

ASKER

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") &
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
Avatar of GDB08

ASKER

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


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>
Avatar of GDB08

ASKER

Just one record at a time as in the code.
Avatar of GDB08

ASKER

and it repeats:

      rs.movenext
      loop
      rs.close
      set rs = nothing
      cn.close
      set cn = nothing
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
Avatar of GDB08

ASKER

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.
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
Avatar of GDB08

ASKER

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.

ASKER CERTIFIED SOLUTION
Avatar of Wayne Barron
Wayne Barron
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
OK.
This will do it for you.

Carrzkiss
Avatar of GDB08

ASKER

Thanks a lot for your great support :-)
:) 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 :-)