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