Solved

Checkbox Onclick aspx

Posted on 2008-10-15
4
815 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

691 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