www.webdeveloper.com
Results 1 to 5 of 5

Thread: How to add checkbox value to textarea?

  1. #1
    Join Date
    Mar 2004
    Posts
    3

    Question How to add checkbox value to textarea?

    Hi,

    Code:
    function ck()
    {
        //ft.Content.value += ft.ck.value;
        //ft.getElementById('Content').value += ft.getElementById('ck').value;
        ft.getElementById('Content').innerHTML += ft.getElementById('ck').value;
    }
    
    <textarea id="Content" name="Content" rows="5" cols="20"></textarea>
    
    <INPUT id="ck" onclick="ck()" type="checkbox" value="Hello World">
    I want the checkbox value "Hello World" to be appended to textarea by the above js.

    However, it said the object does not support this attribute or method.

    I guess the textarea does not support value. If so, how should I do it?

    Thanks


  2. #2
    Join Date
    Jul 2003
    Location
    Boston Area, Massachusetts
    Posts
    3,489
    Welcome to the forums.
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    	
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    	<head>
    		<title>untitled</title>
    		<meta http-equiv="content-type" content="application/xhtml+xml; charset=iso-8859-1" />
    		<script type="text/javascript">
    		//<![CDATA[
    			function appendValue(t, v)
    			{
    				t.value += v;
    			}	
    		//]]>
    		</script>
    	</head>
    	<body>
    
    		<form action="#">
    			<textarea rows="10" cols="50"></textarea>
    			<input type="checkbox" value="Hello, World!" onclick="if(checked) appendValue(elements[0], value);" />
    		</form>
    	</body>
    </html>

  3. #3
    Join Date
    Jun 2003
    Location
    The United States Site: http://kellyj.t35.com
    Posts
    2,561
    Since we are saying Hello to the World , maybe you'll know this fred. Why do so many sources list the Hello, World! with and so many without the comma.

  4. #4
    Join Date
    Jul 2003
    Location
    Boston Area, Massachusetts
    Posts
    3,489
    Just different preferences, I guess. Though, traditionally, "Hello, World" is the first program someone writes when learning a new language.

  5. #5
    Join Date
    Mar 2004
    Posts
    3
    Hi,

    I would like to know how can the textarea onchange be called by js.

    e.g. When I click the checkbox, add value to textarea, textarea can detect it is changed (like refresh). Because I have another js to count the number of words in the textarea.

    I put document.Content.onchange in last line of the js.
    Code:
    document.getElementById('Content').value += document.getElementById('ck').value;
    document.Content.onchange //how can refresh the textarea for change?
    It has error.

    How can I fix it?

    Thanks for help.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles