...

View Full Version : Comma Seperated STring



compu17053
05-26-2004, 02:51 PM
Hi
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


<script>
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 ""
}
</script>
<form>
<table border =1>
<tr>
<td>Select</td>
<td>Name</td>
<td>Description</td>
<td>Text</td>
</tr>
<tr>
<td><input type="checkbox" value="1" onClick="this.form.output.value=getChecked(this.form)"
value="s1,S1Name"></td>
<td>s1</td>
<td>S1Name</td>
<td><input type="text" name="input1" value=""></td>
</tr>
<tr>
<td><input type="checkbox" value="2" onClick="this.form.output.value=getChecked(this.form)"
value="s2,S2Name"></td>
<td>s2</td>
<td>S2Name</td>
<td><input type="text" name="input2" value=""></td>
</tr>
<tr>
<td><input type="checkbox" value="3" onClick="this.form.output.value=getChecked(this.form)"
value="s3,S3Name"></td>
<td>s3</td>
<td>S3Name</td>
<td>S3Text</td>
</tr>
</table>
Output:<input type="text" name="output" value="">
</form>

sad69
05-26-2004, 08: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.

Sadiq.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum