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

Checkbox value 2

Status
Not open for further replies.

JustWondering

Technical User
Jun 28, 2003
57
US
Hi,

I have an SQL update based on the value of the checkboxes:
Code:
SQL="Update Table Set Status = " & CInt(Request("chkStatus")) & " Where ID = " & IntID

But I couldn't get the value of the checkboxes. I always update with checkbox's value = 0.

Here is my checkboxes

Code:
<%Do While NOT RsData.EOF%>
<tr><td>Status<input type=&quot;checkbox&quot; name=&quot;chkStatus&quot; value=&quot;<%Rs(&quot;Status&quot;)%>&quot;>
<%RsData.MoveNext
Loop%>

I guess I'm missing the code to capture the value of the checkboxes. Someone please help!
 
Sorry if this is a stupid question, but do you have your checkboxes in a form?

You'll need to surround them in form tags and submit them to the next page with a Submit button.

If that's not it, try viewing your source on the ASP page. Make sure that the value=&quot;<%Rs(&quot;Status&quot;)%>&quot; is returning something. Perhaps the problem isn't in your check boxes, but rather in your result set?

I presume these are two different pages, one submitting to another. Any other information might also be helpful.

RJ

************
RudeJohn
************
 
Actually try this:

for i=1 to request(&quot;chkStatus&quot;).count
SQL=&quot;Update Table Set Status = &quot; & CInt(Request(&quot;chkStatus&quot;)(i)) & &quot; Where ID = &quot; & IntID
cn.execute mysql

next
 
Thank you for your response.

Yes, they are all in a form. The form is in a table. And I have submit button to do the update. The method=post action=samepage.

 
If this is a serious production database, putting an update into a loop (and updating once for each check box) is extremely inefficient, when you only want one value.

Where are you getting IntID? Does it matter to the database? I would presume that you're capturing that in another part of the form, and that you only want to make one database update, based on that ID.

thread333-628173

************
RudeJohn
************
 
Let me explain what I'm trying to achieve.

First I select and display those records which have the Status=0.

Job5 Status=0
Job7 Status=0
Job11 Status=0

Then I update them, depends on their values if users checked them or not. Each records has a ID. And I'm trying to update each records based on the values of the checkbox and the ID.

It is not a serious database. It's just a small table.
 
Well, actually, it didn't work corectly. If there are 5 checkboxes and I randomly check 2. It just update the first 2.

Beacuse ecah record has it own ID. I used this:
Code:
for i=1 to request(&quot;chkStatus&quot;).count
SQL=&quot;Update Table Set Status = &quot; & CInt(Request(&quot;chkStatus&quot;)(i)) & &quot; Where ID = &quot; & Request(&quot;txtID&quot;)
cn.execute mysql

But it didn't work correctly like I said.
 
I also tried this:

Code:
for i=1 to request(&quot;chkStatus&quot;).count
SQL=&quot;Update Table Set Status = &quot; & CInt(Request(&quot;chkStatus&quot;)(i)) & &quot; Where ID = &quot; & CInt(Request(&quot;txtID&quot;)(i))
cn.execute mysql

...not working...Anyone know why???
 
Actually there is a problem there.

If you have same name on the checkboxex they wont come to server as an colection so Request.Form().Count wont work or at least should be 1 element. Naming 2 or more checkboxes the same it will group them.

I presume that you have each group of checkboxes for each line(Jobs as i see)
So if you want to have diferents groups of checkboxes for each you should name them for each Jobs

while not rsJobs.Eof
Response.Write rsJobs(&quot;JobName&quot;)
'....
while not rsStatus.Eof
...
<input type=&quot;checkbox&quot; name=&quot;chkStatus<%=rsJobs(&quot;jobID&quot;)%>&quot; value=&quot;<%Rs(&quot;Status&quot;)%>&quot;>
%>
...
rsStatus.MoveNext
whend
rsJobs.MoveNext
whend

naming same all the checkboxex for a job, but not all for all jobs.

now you knw the jobID

and can get the
jobID=request.form(&quot;jobID&quot;)
status=request.form(&quot;chkStatus&quot;&jobID)
and make your update.

1 more thing. do you have for each line(job) a seperate submit form or you using same form for each line.

________
George, M
 
Try setting your variable like this:

CInt(Request(&quot;chkStatus&quot; & i))

--------------------------------------------------------------------------------------------------------------------------
Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so.
--Douglas Adams
 
Thanks for all the inputs.

Each job and status are fileds in a record.

ID Job# Status Date

All the records are displayed in 1 form with same submit button.


CInt(Request(&quot;chkStatus&quot; & i)) : This won't work either.
 
I think the value of the checkbox was lost. When I check the box and try to catch its value, it return False or 0.

 
The values of all the checkboxes when the form is load are zeros. If the a box is check, how can I change its value to zero?

<%Do While NOT RsData.EOF%>
<tr><td>Status<input type=&quot;checkbox&quot; name=&quot;chkStatus&quot; value=0>
<%RsData.MoveNext
Loop%>
 
Clear some things up about checkboxes.
When you submit a form a checkbox value is only passed if it is checked i.e. if not checked then you can't use request.form to see what its value is (if its checked or not checked)
The value you set in a checkbox will be the value that is passed to the next page if it is checked.

e.g.
<input type=checkbox name=chkbox1 value=1>
<input type=checkbox name=chkbox2 value=1>
<input type=checkbox name=chkbox3 value=1>

Now someone checks the checkbox named chkbox2 and submits. On the next page when you do ...
request.form(&quot;chkbox1&quot;) ' No value - no object to check
request.form(&quot;chkbox2&quot;) ' Return value is 1
request.form(&quot;chkbox3&quot;) ' No value - no object to check

Only having quickly run thru this thread what you should be doing is

<%Do While NOT RsData.EOF%>
<tr><td>
Status
<input type=&quot;checkbox&quot; name=&quot;chkStatus<%=rs(&quot;ID&quot;)%>&quot; <%if rs(&quot;Status&quot;)=1 then response.write &quot; checked &quot; %> value=&quot;1&quot;>
<%RsData.MoveNext
Loop%>

Here I'm assuming rs(&quot;status&quot;) holds 1 or 0, 1 meaning Yes checked and 0 meaning No not checked
Now you also have a uniquely named checkbox for each record.
Then when you come to do the update

<%
if request(&quot;chkstatus&quot;&IntID)=1 then status=1
SQL=&quot;Update Table Set Status = &quot; & status & &quot; Where ID = &quot; & IntID
%>


Remember this assumes the Status field should be 1 or 0



 
Change on the last bit

<%
if request(&quot;chkstatus&quot;&IntID)=1 then status=1 else status=0
SQL=&quot;Update Table Set Status = &quot; & status & &quot; Where ID = &quot; & IntID
%>




 
Yes, the value of status is o 0r 1 in the table. However, my SQL statement only those that have Status = 0 to display.

SQL=&quot;Select from Table where Status=0&quot;

Let say it returns 10 records. Now user check 5 of them. The Update statement should update the right 5 records. Right now, it just update the first 5 in the list.
 
Select * from Table where Status = 0

Items to be displayed:

ID Status
55 0
68 0
77 0

The IDs are displayed in as lable, Status as checkboxes.

User can update the table by checking the box.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top