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 5 of 5
  1. #1
    New Coder
    Join Date
    Dec 2005
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy $(currentID).onclick = ERRORZ

    Last post i promise.
    Code:
    $(currentID).onclick = "grow('+currentID+','+oheight+','+theight+','+twidth+','+margin+')";
    Doesn't provide any errors - but neither does it work.

    I need to put these variables into the onclick function.

    i can use
    Code:
    $(currentID).onclick = grow;
    but this does not allow me to assign variables.

    PS. $ is shorthand for document.getElementByID as found in prototype framework.

  • #2
    New Coder
    Join Date
    Dec 2005
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    it seems that even the line
    Code:
    	$(currentID).onclick = alert('chump');
    doesn't work - instead of alerting onclick, it alerts as soon as the script arrives at that point and gives the error:-
    Error: Not Implemented

  • #3
    New Coder
    Join Date
    Dec 2005
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    this is the function in full

    Code:
    function shorten(){
    	if(height>oheight){
    	height = height - 4;
    	margin = margin + 2;
    	$(currentID).style.height = height+"px";
    	$(currentID).style.marginTop = margin+"px";
    	growtimer[currentID] = setTimeout(function(){ shorten(); },1);
    	}else{
    	lock = false;
    	$(currentID).onclick = alert('chump');
    	}
    }

  • #4
    New Coder
    Join Date
    Dec 2005
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    	$(currentID).onclick = function(){ grow(currentID,oheight,theight,twidth,margin); }
    FIXED

    Although this was a guess, if anyone wants to explain to me why this works then feel free

  • #5
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Browsers like using setAttribute however IE doesn't like it when you are trying to set an event handler using setAttribute so you must use an anonymous function like you have done in your last post.
    ||||If you are getting paid to do a job, don't ask for help on it!||||


  •  

    Posting Permissions

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