JS check box to pass the value of the multi-selection effect to a text box

Source: Internet
Author: User

Select a check box, then the value of this check box is passed to a text box, if the text box is not added, no Add. If deselected, the passed value is removed from the text box. The middle is separated by "," and the last end has no "," delimiter.

<!DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd ">    <HTMLxmlns= "http://www.w3.org/1999/xhtml">    <Head>    <Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" />    <title>JS check box to pass value to a text box multi-select effect 丨 Shijiazhuang steel structure | Shijiazhuang car Audio</title>    <styletype= "Text/css">input{Margin-right:3px}label{margin:0 5px}    </style>    <Scripttype= "Text/javascript">window.onload= function(){    varObox=document.getElementById ("Box"); varcbolist=Obox.getelementsbytagname ("input"); varOtext=document.getElementById ("TT"); document.getElementById ("Box"). onclick= function(e) {varsrc=e?e.target:event.srcelement; if(Src.tagname== "INPUT"){    varValues= [];  for(varI=0; I<Cbolist.length;i++){    if(cbolist[i].checked) {Values.push (cbolist[i].value); }} Otext.value=Values.join (","); }    }    }    </Script>    </Head>    <Body>    <P><inputtype= "text"ID= "tt" /></P>    <DivID= "box">    <label><inputtype= "checkbox"value= "a" />A</label>    <label><inputtype= "checkbox"value= "B" />B</label>    <label><inputtype= "checkbox"value= "C" />C</label>    <label><inputtype= "checkbox"value= "D" />D</label>    <label><inputtype= "checkbox"value= "E" />E</label>    <label><inputtype= "checkbox"value= "F" />F</label>    </Div>    </Body>    </HTML>    <BR><BR><HR>    

JS check box to pass the value of the multi-selection effect to a text box

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.