Asp. NET in the use of JS to take the value of CheckBoxList Method Example _ practical skills

Source: Internet
Author: User

Do some projects are relatively small, and time tight, there are a lot of things have not come to a hasty summary, while this will have a little time to use the previous project to share the knowledge, only for later convenience.
Front page code

Copy Code code as follows:

<!--keyword-->
<div id= "Keywordsdiv" style= "border:2px solid #6FA1D9; Display:none; Position:absolute;
top:0px; left:0px; width:260px; height:120px; Z-index:3; Background-color: #EAF1FD; " >
<div style= "width:260px; height:20px; Background-color: #6FA1D9 ">
<ul style= "Cursor:pointer; line-height:20px; " >
<li style= "Float:right" onclick= "Getcheckvale ()" >[determine]</li><li style= "Float:right"
Onclick= "Closeself ()" >[shutdown]</li></ul>
</div>
<div>
<asp:checkboxlist id= "cblkeywords" runat= "Server" repeatcolumns= "2" >
</asp:CheckBoxList>
</div>
</div>

JS Script
Copy Code code as follows:

Open the Keyword window
function Locking (E)
{
var divleft = E.offsetleft;
var divtop = e.offsettop;
while (e=e.offsetparent)
{
Divleft + = E.offsetleft;
Divtop + = E.offsettop;
}
var divobj = document.getElementById ("Keywordsdiv");
DivObj.style.left = divleft+ "px";
DivObj.style.top = divtop+20+ "px";
DivObj.style.display = "block";
}
Close the Keyword window
function Closeself ()
{
Document.all.keyWordsDiv.style.display = ' None ';
var Objcheck = document.getElementById ("Cblkeywords"). getElementsByTagName ("input");
for (var i = 0; i < objcheck.length; i++) {
document.getElementById ("Cblkeywords_" + i). checked = false;
}
return false;
}
Keyword values
function Getcheckvale ()
{
var Objcheck=document.getelementbyid ("Cblkeywords");
var Objcheck=document.getelementbyid ("Cblkeywords"). getElementsByTagName ("input");
var Objlabel = document.getElementById ("Cblkeywords"). getElementsByTagName ("label")
var txtkeywordsvalue = "";
var m=0
for (Var i=0;i<objcheck.length;i++)
{
if (document.getElementById ("Cblkeywords_" +i). Checked)
{
var idcheck =document.getelementbyid ("Cblkeywords_" +i). id;//The ID of the currently selected checkbox
for (var j = 0;j <objlabel.length;j++)
{
var forvalue=objlabel[j].getattributenode ("for"). Value
if (Forvalue = = Idcheck)
{
M+=1;
for (Var k=0;k<m;k++)
{
if (k==m-1)
{
txtkeywordsvalue+=objlabel[j].innerhtml;
}
Else
{
Txtkeywordsvalue + = "|" +objlabel[j].innerhtml;
Break
}
}
}
}
}
}
document.getElementById ("Txtkeywords"). Value=txtkeywordsvalue;
Document.all.keywordsdiv.style.display= ' None ';
}

Add a button to call JS
Copy Code code as follows:

<asp:textbox id= "txtkeywords" runat= "Server" readonly= "True" class= "INP" ></asp:TextBox>
<input id= "Imgkey" type= "button" runat= "Server" onclick= "Locking (This)" class= "Tailbut" value= "select"/>

Well, the code is so much, click on the button after the pop-up layer, select the check box can really take the value, the following look at the effect bar!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.