Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Aug 6th, 2005, 2:58 PM   #1
sbells
Newbie
 
Join Date: Jan 2005
Posts: 6
Rep Power: 0 sbells is on a distinguished road
javascript: retrieve datagrid checked items in confirm box

Experts,

i have a datagrid with 2 template columns,checkbox[databound] and label control.
The user can check multiple checkboxes in the datagrid and click on the "Add" button to add the checked items.
My problem is the client-side validation.
I need the user to confirm the addition of checked items.so,i need to display a pop-up window which will ask the user "Are you sure you want to add the following items?" and below must be a list of all checked items i.e.,the text of databound template?

Please guide me ..this is really important!!
Thanks!
sbells is offline   Reply With Quote
Old Aug 7th, 2005, 7:57 AM   #2
Cerulean
Professional Programmer
 
Cerulean's Avatar
 
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4 Cerulean is on a distinguished road
Firstly you want to catch the event that is fired before the forum is submitted. To do that, in your submit button add an onsubmit handler that calls a function:
<form id="form1">
  <input type="checkbox" ...
  <input type="submit" onsubmit="return validateData()" />
</input>
In the validateData function we can just get a reference to the form element with an ID of 'form1', and then go through all of it's checkboxes, and see which ones are checked and then tell the user.
function validateData() {
    form = document.getElementById("form1");
    // Loop through all of the input elements in the form..
    for(var i = 0; i < form.elements.length; ++i) {
        // If the element is a checkbox, and it is checked
        if(i.getAttribute("type") == "checkbox" && i.checked) {
            // Then add this checkbox to a list or whatever.
        }
    }
    return confirm("Are you sure you want to ...")
}
Cerulean is offline   Reply With Quote
Old Aug 7th, 2005, 10:35 AM   #3
sbells
Newbie
 
Join Date: Jan 2005
Posts: 6
Rep Power: 0 sbells is on a distinguished road
But, how can i append the confirm message with the text of checked items which are databound...??? Do i use innerText of checkbox control to retrieve the text of checked items and put it in a variable and then concatenate it to the confirm message??
sbells is offline   Reply With Quote
Old Aug 7th, 2005, 11:39 AM   #4
Cerulean
Professional Programmer
 
Cerulean's Avatar
 
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4 Cerulean is on a distinguished road
How are the checkboxes and text mapped to each other? Via label elements with the for attribute set to the ID of the corresponding checkbox?
Cerulean is offline   Reply With Quote
Old Aug 7th, 2005, 1:31 PM   #5
sbells
Newbie
 
Join Date: Jan 2005
Posts: 6
Rep Power: 0 sbells is on a distinguished road
not label...but used container.databind...to the dataset
sbells is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:38 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC