PDA

View Full Version : Checkbox's to Populate Textbox


NICKGE1
10-15-2002, 11:37 AM
Hi,

I've got a list of 4 checkbox's I'd like to populate a textbox on my view. So that if checkbox's 1 and 2 are checked they appear in the text box value as "1, 2"

I know this should be easy but I'm still very new to this. Can anyone give me some pointers.

Thanks

My checkbox's look like this

<input type="checkbox" name="checkbox1" value=1>
<input type="checkbox" name="checkbox1" value=2>
<input type="checkbox" name="checkbox1" value=3>
<input type="checkbox" name="checkbox1" value=4>

chrismiceli
10-15-2002, 01:57 PM
don't have time to go into detail but try something like this


function hi(num) {
document.forms[0].textbox.value += num;
}

<input type="radio" onClick="hi(1)">
<input type="text" name="textbox" value="">

adios
10-15-2002, 06:01 PM
<html>
<head>
<title>untitled</title>
<script type="text/javascript" language="javascript">

function display(box) {
// get reference to form object, and to array of same-named checkboxes
var temparr = new Array(), f = box.form, boxgroup = f[box.name];
// loop through it
for (var i=0; i<boxgroup.length; i++) {
// add the value of any checked box to next available slot in temparr
if (boxgroup[i].checked) temparr[temparr.length] = boxgroup[i].value;
// run the .join() method on the array (separator = ',') and output it to field
f.readout.value = temparr.join(',');
}
}

</script>
</head>
<body onload="document.forms[0].reset()">
<form>
<!-- display(this) passes a reference to the checkbox object to the function -->
<input type="checkbox" name="group" value="1" onclick="display(this)"> 1
<input type="checkbox" name="group" value="2" onclick="display(this)"> 2
<input type="checkbox" name="group" value="3" onclick="display(this)"> 3
<input type="checkbox" name="group" value="4" onclick="display(this)"> 4
<br><input type="text" name="readout" size="20">
</form>
</body>
</html>

NICKGE1
10-16-2002, 10:22 AM
That worked a treat,

I had managed to get my box to become populated but was having trouble when the somone un-checked the values. You read my mind thanks a lot.

Nick