about DOM -getElemenybyId

Discussion in 'JavaScript' started by progfrog, Jan 20, 2008.

  1. #1
    hi everyone:
    I have a problem with a small function I wrote to practice the getElementbyId method - the function i wrote can be made without this method but i wanted to practice it - why doesn't it run?


    need u guys quickly

    progfrog


    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1255 ">
    <script type="text/javascript">
    function michal(x) {


    var checky=document.getElementById(x)



    if (idan.checky.checked) {
    idan.comment1.style.display="none";
    }
    else {
    idan.comments1.style.display="block";

    }
    </script>
    </head>

    <body>
    <form id="idan">
    <input type="checkbox" id="check1" onclick="michal('check1')" checked /><textarea id="comments1" cols="30" rows="7">I think that</textarea>
    <br>

    </form>
    </body>
    </html>
     
    progfrog, Jan 20, 2008 IP
  2. webexpert

    webexpert Banned

    Messages:
    188
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    idan.comment1.style.display="none";

    comment1 here should be comments1 ... "s" is missing :)
     
    webexpert, Jan 20, 2008 IP
  3. progfrog

    progfrog Peon

    Messages:
    73
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    hi webexpert
    i added the s and is still doesn't work- is there anything elese here that is not o.k- did you manafed to run this in your computer? need u again
    progfrog
     
    progfrog, Jan 20, 2008 IP
  4. webexpert

    webexpert Banned

    Messages:
    188
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    alright - i made it functional now...

    try this code;

    <script type="text/javascript">
    function michal(x) {


    var checky=document.getElementById(x);

    if (checky.checked) {
    idan.comments1.style.display="none";
    }
    else {
    idan.comments1.style.display="block";

    }
    }
    </script>

    i replaced if (idan.checky.checked) with if (checky.checked)

    and the function ending brace was missing..

    enjoy..
     
    webexpert, Jan 20, 2008 IP