473,396 Members | 1,866 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

how to update record based on checkbox selection

254 100+
Hi

I want to update records in database based on selected records using checkbox. if user does not select a record and clicks update button it should show the message please select record to be update
if user selects say 3 records then there should be message are you sure to update 3 records and when clicks ok records should get updated.

since records are coming dynamically so how can I get the number of checkboxes selected or not to display message using javascript. and then when i will write query to update then how will I retrieve the value of checkbox based on which records will be updated.

in checkbox I am passing the id of the records
Mar 28 '09 #1
6 4049
Markus
6,050 Expert 4TB
To pass an array of checkboxes (checkboxes that a grouped by some definition) you must name them suffixed with brackets (name="checkboxes[]"). Then, I assume you're POSTING, you retrieve them via $_POST['checkboxes']. Use a count() on the array to see if any checkboxes were passed.
Mar 28 '09 #2
mukeshrasm
254 100+
@Markus
Yes I am using $_POST to retrieve but how will retrieve the value of checkbox means should I use loop or it will be display all checkboxes value since it is array.
Mar 30 '09 #3
Markus
6,050 Expert 4TB
@mukeshrasm
Yes, a loop.

Expand|Select|Wrap|Line Numbers
  1. if ( count ( $_POST['checkboxes'] ) > 0 )
  2. {
  3.     foreach ( $_POST['checkboxes'] as $key => $val )
  4.     {
  5.         // $val holds the value of your checkbox
  6.         // $key is the index in the array of said checkbox.
  7.     }
  8. }
  9.  
Mar 30 '09 #4
mukeshrasm
254 100+
@Markus
Thanks! for this and I think this will solve my purpose..
Mar 31 '09 #5
Markus
6,050 Expert 4TB
@mukeshrasm
You're welcome.

Post back with any problems.

- Mark.
Mar 31 '09 #6
mukeshrasm
254 100+
@Markus
Hi

using javascript I tried to find the no. of checkboxes selected. I used like


Expand|Select|Wrap|Line Numbers
  1. var lengthh=document.getElementsByName("chk[]").length            var j=0;
  2.             for (i=0, l=lengthh; i<l; i++)
  3.             {
  4.                                if (document.getElementsByName("chk[]").checked==true)  //here I don't know how I will loop through to find the number of checkboxes selected.
  5.                 {
  6.                      j++;
  7.                }
  8.            }
  9.           if (j==0)
  10.           {
  11.              alert("Please Select Record to delete!")
  12.           }
  13.     else     {
  14.      confirm("Do you really want to remove selected "+ j +" items" )
  15.      }
  16.    }
  17.  
  18.  
and one more interesting thing when I click "Cancle" button of Confirm message event also get fired i.e. it deletes the record.
Apr 6 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Sue Adams | last post by:
I actually have two issues/questions: I have an autonumber field in an access db table that I grab and later use to update a record in another table withing the same db. The code I use to get...
5
by: A.Dagostino | last post by:
hi i need to update an SQL Table when user select or unselect a checkbox control. How Can i do? Thanks Alex
11
by: Siv | last post by:
Hi, I seem to be having a problem with a DataAdapter against an Access database. My app deletes 3 records runs a da.update(dt) where dt is a data.Datatable. I then proceed to update a list to...
6
by: MLH | last post by:
When the vehicle entry form (frmVehicleEntryForm) first opens, the additional owner SubForm control (frmAddnlOwnrListSubForm) is enabled. You can click on it and it will accept the focus. But after...
16
by: Ian Davies | last post by:
Hello Needing help with a suitable solution. I have extracted records into a table under three columns 'category', 'comment' and share (the category column also holds the index no of the record...
0
by: uthooker | last post by:
I have an Access form with some combo boxes in the Form Header that are enabled/disabled using conditional formatting based on the setting in a checkbox also in the Header (Combo box = Enabled by...
2
by: BOS | last post by:
Hi there, I just create a form that contains name, Address, City, State, Zip, Question Checked box, and dropdown list selection for the user to fill-out the answer in the texbox, checkbox or...
1
by: hmlarson | last post by:
I have a form/table with checkboxes that I would like the user to check / uncheck if they want a certain record to display in a gallery on a website. I'm having problems figuring out how to...
2
by: sirdavethebrave | last post by:
Hi guys - I have written a form, and a stored procedure to update the said form. It really is as simple as that. A user can go into the form, update some fields and hit the update button to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.