?
Solved

Confirm javascript

Posted on 2013-01-28
2
Medium Priority
?
280 Views
Last Modified: 2013-01-29
i want a confirm javascript. i dont want the pop up to show up on a button click or any other event. instead i want it show up  when i do the following

"i have a datagrid with check boxes and when multiples rows are selected i want a confirm pop up ."
0
Comment
Question by:pratikshahse
2 Comments
 
LVL 41

Accepted Solution

by:
guru_sami earned 1000 total points
ID: 38829281
Here's sample code to start:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
    <script  type="text/javascript">
        $(function () {
           $("#btnSave").click(function () {
                var checkedboxes =$("#dataTable  input:checkbox:checked").length;
                if (checkedboxes > 1)
                    return confirm("Do you want to Save " + checkedboxes + " records");
                else
                    return true;
            });
        });
</script>

<table id="dataTable">
            <tr>
                <td>
                    <asp:CheckBox ID="chb1" runat="server" Text="One" />
                </td>
            </tr>
            <tr>
                <td>
                    <asp:CheckBox ID="CheckBox1" runat="server" Text="Two" />
                </td>
            </tr>
        </table>
        <asp:Button ID="btnSave" runat="server" Text="Button" />

Open in new window

0
 
LVL 10

Assisted Solution

by:Monica P
Monica P earned 1000 total points
ID: 38830619
USe "onchange" event of checkbox u have in your design

http://stackoverflow.com/questions/2697329/get-number-of-checkboxes-that-are-checked-in-javascript


   <input type="checkbox" onclick="OnChangeCheckbox (this)" id="myCheckbox" />

Open in new window

 <script type="text/javascript">
        function OnChangeCheckbox (checkbox) {
            if (checkbox.checked) {
                alert ("The check box is checked.");
            }
            else {
                alert ("The check box is not checked.");
            }
        }
    </script>

Open in new window



check number of checkbox count using

var cnt = $('.chkBoxList input:checked').length;

Open in new window

0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Loops Section Overview
Suggested Courses

755 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