Solved

Saveing value from checkbox

Posted on 2009-05-14
17
396 Views
Last Modified: 2012-08-13
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

0
Comment
Question by:GDB08
  • 9
  • 8
17 Comments
 

Author Comment

by:GDB08
ID: 24385251
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
 
LVL 30

Expert Comment

by:Wayne Barron
ID: 24385476
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
 
LVL 30

Expert Comment

by:Wayne Barron
ID: 24385482
sorry

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

Carrzkiss
0
 

Author Comment

by:GDB08
ID: 24385711
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
 
LVL 30

Expert Comment

by:Wayne Barron
ID: 24385804
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
 

Author Comment

by:GDB08
ID: 24386113
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
 
LVL 30

Expert Comment

by:Wayne Barron
ID: 24386272
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
 

Author Comment

by:GDB08
ID: 24386288
Just one record at a time as in the code.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:GDB08
ID: 24386298
and it repeats:

      rs.movenext
      loop
      rs.close
      set rs = nothing
      cn.close
      set cn = nothing
0
 
LVL 30

Expert Comment

by:Wayne Barron
ID: 24386327
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
 

Author Comment

by:GDB08
ID: 24386404
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
 
LVL 30

Expert Comment

by:Wayne Barron
ID: 24386474
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
 

Author Comment

by:GDB08
ID: 24386657
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
 
LVL 30

Accepted Solution

by:
Wayne Barron earned 500 total points
ID: 24386698
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
 
LVL 30

Expert Comment

by:Wayne Barron
ID: 24386705
OK.
This will do it for you.

Carrzkiss
0
 

Author Closing Comment

by:GDB08
ID: 31581466
Thanks a lot for your great support :-)
0
 
LVL 30

Expert Comment

by:Wayne Barron
ID: 24387026
:) 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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now