1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

DOM- i need you guys

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?

    please try to run it before answer I don't understand what can go wrong?


    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. SoKickIt

    SoKickIt Active Member

    Messages:
    305
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    70
    #2
    function michal(x)
    {
    	var checky = document.getElementById(x);
    
    	if(checky.checked)
    	{
    		document.getElementById('comments1').style.display = "inline";
    	}
    	else
    	{
    		document.getElementById('comments1').style.display = "none";
    	}
    }
    Code (markup):
    Let me know if you don't understand how it works.
     
    SoKickIt, Jan 20, 2008 IP
  3. MMJ

    MMJ Guest

    Messages:
    460
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #3
    var checky = document.getElementById(x);
    document.getElementById('comments1').style.display = checky.checked ? "inline" : "none"
    PHP:
     
    MMJ, Jan 20, 2008 IP
  4. webexpert

    webexpert Banned

    Messages:
    188
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    hello, i already replied you in your another thread with same question.. here it is again for you with corrections;

    <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 (checky.checked) {
    idan.comments1.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>

    what fixings i have done in your code:

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

    2) "s" was missing in the comments spelling idan.comment(s)1.style.display="none";

    3) you missed to close the function end brace }

    thatz all...
     
    webexpert, Jan 22, 2008 IP