Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    May 2004
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Comma Seperated STring

    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

    Code:
    <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>
    Last edited by liorean; 05-26-2004 at 09:58 PM. Reason: [Code]ified

  • #2
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •