Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: short script that's bugging me.

  1. #1
    Join Date
    Nov 2006
    Posts
    236
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default short script that's bugging me.

    just why can't this work. I've used many scripts and can't figure out why this wont work. I think the script doesn't like the ct++ and ct--



    in the head

    var ct=50;
    var vis=0;


    function show(contain){
    var van = document.getElementById(contain).style.display;
    var heit=document.getElementById(contain).style.height;

    document.getElementById(contain).style.height.ct+'px';

    ct++;


    if (ct==51){
    document.getElementById(contain).style.display="block";



    if (ct<140)
    setTimeout('show()',10);
    }



    function revers() {

    van = document.getElementById(contain).style.height=ct+'px';
    ct--;

    if (ct<6)

    document.getElementById(contain).style.display='none';
    if (ct>5)
    setTimeout('revers()',0);


    }

    in the body
    <div id="contained" class="linkem" onclick="show('vanish')" >
    on a side note if I also wanted to count up or down the opacity and I know the fliters and ways browsers use opacity how can I attach it to the ct-- ct++
    so it toggles opacity as well.

  2. #2
    Join Date
    May 2006
    Location
    Alaska
    Posts
    163
    Thanks
    5
    Thanked 2 Times in 2 Posts

    Default

    For one thing:
    Code:
    document.getElementById(contain).style.height.ct+'px';
    Ought to be
    Code:
    document.getElementById(contain).style.height = ct+'px';
    The first one probably throws a syntax error.

    You need one "}" to end this:
    Code:
    if (ct==51){
    document.getElementById(contain).style.display="block";
    And another to end:
    Code:
    function show(contain){
    Hope this helps,
    Stephen
    Last edited by ???; 08-19-2008 at 05:55 PM.

  3. #3
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Stephen, actually (s)he is ending:
    Code:
    if (ct==51){
    document.getElementById(contain).style.display="block";
    Double check it.
    Jeremy | jfein.net

  4. #4
    Join Date
    May 2006
    Location
    Alaska
    Posts
    163
    Thanks
    5
    Thanked 2 Times in 2 Posts

    Default

    Really? Maybe I messed up but I count 6 functions and if statements, and 2 "}"s. Some ofe the functions and if's don't even have "{"s.
    I always indent to make sure I've got the right number.

  5. #5
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Yes, the if() had the } and function didn't.
    Jeremy | jfein.net

  6. #6
    Join Date
    May 2006
    Location
    Alaska
    Posts
    163
    Thanks
    5
    Thanked 2 Times in 2 Posts

    Default

    Here I cleaned up the code a little and made it easier to read (I think). I was guessing a little so you might have to change some. Also you probably want to remove my comment.
    Code:
    var ct = 50;
    var vis = 0;
    function show (contain){
    	var van = document.getElementById (contain).style.display;
    	var heit = document.getElementById (contain).style.height;
    	document.getElementById (contain).style.height = ct + "px";
    	ct ++;
    	if (ct == 51){
    		document.getElementById (contain).style.display = "block";
    		if (ct < 140)
    			setTimeout (function () { show (contain); },10);
    		}
    	}
    	function revers () {
    		van = document.getElementById (contain).style.height = ct + "px";
    		ct --;
    		if (ct < 6)
    			document.getElementById (contain).style.display = "none";
    			if (ct > 5)
    				//Why this vvv it istantly calls it why not do "revers ()"
    				setTimeout (function () { revers (); },0);
    			}
    		}
    	}
    }

  7. #7
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Instead of ct++ and ct-- Try:
    ct += 1 and ct -= 1
    Jeremy | jfein.net

  8. #8
    Join Date
    May 2006
    Location
    Alaska
    Posts
    163
    Thanks
    5
    Thanked 2 Times in 2 Posts

    Default

    I always do ct = ct + 1, but it was his code so I didn't change it.

  9. #9
    Join Date
    Nov 2006
    Posts
    236
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default

    wow I didn't catch that first error. I never even threw one. anyhow I hope to change the opacity as well and I want to use the same settime out function I've had two settime out functions running and it was slow.

    document.getElementById (contain).style.opacity
    or
    document.getElementById (contain).style.var_that_holds_browser_opacites.
    or another object and not a var.

  10. #10
    Join Date
    Nov 2006
    Posts
    236
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default

    I was trying to get on here earlier but the forums must have been down or something.

    that code wont work. do you think there is some limit to passing an id to a function. like if there are things that can't be used with it.
    I just tryed ???'s corrections then with nile's still nothing. the error it throws is in the body tag( not helpful)

    As far as I can tell the script inall the form I've made or tried
    it looks like it has a problem with (c++, c+=1) using document.getElementId() with a real ID works. and I had got the script to add the value of ct but never c++ C--

    does anyone have an idea why when pasing the an ID to a function, that function will not increment any variable?

Bookmarks

Posting Permissions

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