View Full Version : Comma Seperated STring

05-26-2004, 03:51 PM
The script only returns whatever is written in the texbox
Can anybody help me in this

whereas when i click the 3rd checkbox the string returned should be s3,s3Name,s3text

When i enter data "222" in the 2nd rows textbox and click the 2 & 3rd checkbox the string returned should be

s2,s2Name,22|s3,s3Name,s3Text in the Output textbox

function getChecked(theForm)
str = ""
for (i=0;i<theForm.elements.length;i++)
if (theForm.elements[i].type=='checkbox' && theForm.elements[i].checked)
str += "|"+theForm.elements["input"+theForm.elements[i].value].value
if (str) return str.substring(1); // remove leading '|'
else return ""
<table border =1>
<td><input type="checkbox" value="1" onClick="this.form.output.value=getChecked(this.form)"
<td><input type="text" name="input1" value=""></td>
<td><input type="checkbox" value="2" onClick="this.form.output.value=getChecked(this.form)"
<td><input type="text" name="input2" value=""></td>
<td><input type="checkbox" value="3" onClick="this.form.output.value=getChecked(this.form)"
Output:<input type="text" name="output" value="">

05-26-2004, 09:13 PM
Why do you set the value of each checkbox twice? I wasn't even aware that a checkbox could hold a value!

I think you're going about this the wrong way.. your checkboxes don't even have a name. If you want to associate some value with a checkbox, you should probably put that value in a hidden input form field, and name it in such a way so that you know it's associated with the checkbox.