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
    Jun 2010
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Problems with Changing Onclick events on Buttons.

    Hi all,

    I hope that someone can help me with this strange problem I have here.

    I have some script which changes a button and changes the onclick event.

    The strange thing is that although it is changing it. All the events have the same parameter even though my code is giving each button's onclick event it's own unique parameter.

    Here's my Code.
    Code:
    	var AllocPeople = window.opener.document.getElementById('AllocPeople');
    	
    	if(AllocPeople.value.length > 0)
    	{
    		var people = AllocPeople.value.split(",");
    		var Controls = new Array();
    		for(var P in people)
    		{
    			var id = people[P];
    			Controls[P] = document.getElementById('bt_AP_'+id);
    			Controls[P].innerHTML = "Deallocate";
    			Controls[P].onclick = function() {Remove_Player(id)};
    		}
    		
    	}
    Thanking you all in advance.
    Last edited by xfinnerjx; 06-10-2010 at 08:44 PM.

  • #2
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Solved this little problem I was having.

    I've had to make the button changes happen within a separate function to get the required result.

    so my code now look like this:-
    Code:
    function bt_test(id)
    {
    	var bt = document.getElementById('bt_AP_'+id);
    	bt.innerHTML = "Deallocate";
    	bt.onclick = function() {Remove_Player(id)};
    }
    	var AllocPeople = window.opener.document.getElementById('AllocPeople');
    	
    	if(AllocPeople.value.length > 0)
    	{
    		var people = AllocPeople.value.split(",");
    		var Controls = new Array();
    		var ids = new Array();
    		for(var P in people)
    		{
    			bt_test(people[P]);
    		}
    		
    	}
    As this now works I would really like to know why this works when all I have done is seperate the code into functions. When the over all logic is the same.

    Hope someone can explain this to me.

    Thank you all in advance.


  •  

    Posting Permissions

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