Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 6th, 2006, 08:50 AM
Authorized User
 
Join Date: Jun 2006
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Default Javascript Problem

Hi

I have datagrid in asp.net. which contains two columns.And one button name is "save" on my form.

My first column is template column which is checkbox.

Now my Problem is:when i click on save button,I want to check at least one checkbox has to checked.

That's why i want javascript on my save button.How to write javascript for that?

I know hoe to call javascript but how to write means how to take checkbox in javascript?

Thanks
monika





 
Old December 7th, 2006, 02:35 AM
Friend of Wrox
 
Join Date: Aug 2004
Posts: 550
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Monika

Use the javascript method as below:

function ConfirmCheck(objTable)
        {
            //here objTable will be your datagrid name in HTML
var tbl;
            tbl = document.getElementById(objTable);
            var bDecide = false;

            for (var i = 0; i < tbl.rows.length-1; i ++)
            {
                //here _chk will be your checkbox id
var chkBox = document.getElementById(objTable + "__ctl" + (i*1 + 2) + "_chk");

                if(chkBox.checked)
                    bDecide = true;
            }

            if (bDecide == false)
            {
                    alert("Please select a column");
                    return false;
            }
            return true;
        }

To call the method, use below:

 onclick="javascript:return ConfirmCheck('DataGrid1')"

Regards
Mike

Fortune favours the brave, so don't regret on missed oppurtunities.
 
Old December 7th, 2006, 02:39 AM
Friend of Wrox
 
Join Date: Aug 2004
Posts: 550
Thanks: 0
Thanked 1 Time in 1 Post
Default

Well, you can also generalize the above method by passing the checkbox id along with grid name. In case of any issues, let us know.

Regards
Mike

Fortune favours the brave, so don't regret on missed oppurtunities.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Javascript Problem suresh_accudocs ASP.NET 1.0 and 1.1 Professional 1 July 24th, 2007 06:04 PM
javascript problem dk6607 ASP.NET 1.0 and 1.1 Basics 10 October 2nd, 2006 12:56 PM
JavaScript Problem @shish ASP.NET 1.0 and 1.1 Basics 1 April 3rd, 2006 10:26 AM
Javascript Problem dparsons ASP.NET 1.0 and 1.1 Basics 2 March 22nd, 2006 01:41 PM
Javascript problem highcliffevillage Javascript How-To 0 July 8th, 2004 07:13 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.