Click to See Complete Forum and Search --> : checkbox validation


suresh_pendyala
10-20-2003, 11:50 PM
HI,

I have one textbox and multiple checkboxes....whenever i select the checkbox the value should appear in textbox with comma(,)seperated.

ex: 1,2,3,4,5

whenever i deselect the checkbox the selected checkbox value should be removed from the textbox..


send me example....

Charles
10-21-2003, 06:07 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<title>Example</title>

<style type="text/css">
<!--
label {display:block; margin:1em 0em}
button {display:block}
-->
</style>

<form action="">
<div>
<label><input type="checkbox">Fee</label>
<label><input type="checkbox">Fie</label>
<label><input type="checkbox">Foe</label>
<label><input type="checkbox">Fum</label>
<script type="text/javascript">
<!--
for (var i=0; i<document.forms[document.forms.length-1].length; i++) {document.forms[document.forms.length-1].elements[i].onclick = function () {var a = new Array();for (var i=0; i<this.form.elements.length; i++) {if (this.form.elements[i].type == 'checkbox' && this.form.elements[i].checked) a.push (this.form.elements[i].nextSibling.data)};this.form.display.value = a}}

document.write('<input name="display" type="text" disabled>')
// -->
</script>
<button type="submit">Submit</button>
</div>
</form>