Results 1 to 4 of 4

Thread: CheckBox JavaScript Issue

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2005
    Posts
    27

    CheckBox JavaScript Issue

    Hi Everyone,

    I'm trying to get a textbox filled with a 1 or nothing mattering on if the checkbox has been checked. Can someone tell me what I'm doing wrong here?

    Thanks!
    James

    Code:
    <html>
    <head>
    <script language = "JavaScript">
    	function initialChkOO2()
    	{
    		var chkBox = document.getElementById("chk");
    		var txtBox = document.getElementById("text");
    		if(chkBox.Checked)
    		{
    			txtBox.value = "1";
    		} 
    		else
    		{
    			txtBox.value = "";
    		}
    	}
    </script>
    </head>
    <body>
    <form>
    <input type = "checkbox" onClick ="initialChkOO2()" id = "chk" name = "chk"/>
    <input type="textbox" id = "text" name = "text"/>
    </form>
    </body>
    </html>

  2. #2
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: CheckBox JavaScript Issue

    This line:

    Code:
    if(chkBox.Checked)
    Should be:

    Code:
    if(chkBox.checked == true)
    Remember Javascript is case sensative

    Cheers,

    RyanJ
    My Blog.

    Ryan Jones.

  3. #3
    Member
    Join Date
    Mar 2005
    Posts
    56

    Re: CheckBox JavaScript Issue

    Quote Originally Posted by sciguyryan
    This line:
    Code:
    if(chkBox.Checked)
    Should be:
    Code:
    if(chkBox.checked == true)
    Javascript is case sensative, but you don't need == true:
    Code:
    if(chkBox.checked)

  4. #4
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: CheckBox JavaScript Issue

    Yea, true but I always put them for readability sake


    Cheers,

    RyanJ
    My Blog.

    Ryan Jones.

Posting Permissions

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



Click Here to Expand Forum to Full Width