Solved

Checkbox Onclick aspx

Posted on 2008-10-15
4
804 Views
Last Modified: 2012-05-05
Hi experts

I have a checkbox populating from a database

<asp:CheckBoxList ID ="lstStudents" runat="server" CssClass="nowrapping"  DataValueField="PersonId"  DataTextField="DisplayName"  SelectionMode="Multiple" onclick="redir(this)"   ></asp:CheckBoxList>

and  my javascript


function redir(sel){

alert(sel.Value);

}


The result is undefined.

How do I get it  to display the value?

Thanks a lot experts
Nik
0
Comment
Question by:nikdonovanau
4 Comments
 
LVL 7

Expert Comment

by:maXXXeE
ID: 22728676
hi
Please try with
OnClientClick="javascript:redir(this);
(or)
OnClientClick="redir(this)"

instead of
onclick="redir(this)"
0
 
LVL 19

Accepted Solution

by:
Albert Van Halen earned 500 total points
ID: 22735008
Checkboxes on the client don't have values. They have the checked property.
Since ASP.NET is having a so called 'CheckBoxList' control, you will only get the required value server side.
It doesn't mean you can use that logic clientside.

Look in the source of your browser. Each checkbox has a unique id and each checkbox is an individual element (control) in the browser.
0
 
LVL 1

Author Closing Comment

by:nikdonovanau
ID: 31506586
Thanks for that, confirmed my fear so I rewrote the page a different way using hyperlinks and javascript instead.

I managed to output the id of the checkbox but that didnt give me enough info to do what I was after.

Cheers
0
 
LVL 13

Expert Comment

by:sm394
ID: 22736920
Try that

    <script type="text/javascript" language="javascript">

                function getVal() {
            var vals = document.getElementById('div1').getElementsByTagName("label");
            var inputs = document.getElementById('<%=chbListTest.ClientID %>').getElementsByTagName("input");


            for (var i = 0; i < vals.length; i++) {
                if(inputs[i].checked)
                  alert(vals[i].innerText);
            }
        }
    </script>

<button  onclick="getVal()">Get Selected Vals</button>
    <div id="div1">
             <asp:CheckBoxList runat="server" ID="chbListTest">
            <asp:ListItem Text="1" ></asp:ListItem>
            <asp:ListItem Text="2" ></asp:ListItem>
            <asp:ListItem Text="3" ></asp:ListItem>
        </asp:CheckBoxList>
    </div>
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now