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
    Aug 2013
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Accessing check box via id

    Hi Folks,

    In the project there is this external .js file which is linked to a .jsp file. I need to confirm if a certain check box in the .jsp file is checked and I would have to do it from the .js file. Let's say the id for the checkbox is: "fruit".

    I code the following in the .js file:

    if(fruit=="true"){
    console.log('checked');
    }

    somehow, the console statement never gets printed, I am not sure what is wrong with the above mentioned code. Hope someone can advise. Thank you.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,910
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Code:
    if (document.getElementById("fruit").checked){
    // do something
    }
    The boolean true is not the same as the string value "true".

    Q. If you were to spell out numbers, how far would you have to go until you would find the letter "A"?
    A. One thousand

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Tags for this Thread

    Posting Permissions

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