murli800 Posted July 15, 2011 Share Posted July 15, 2011 hi all great coders..i have a problem..i want to change the color of status whenever it is clicked..for elaborating my problem more clearly i am attaching the screenshot of the problem...only color of first row status is changing..even if i am clicking the image of second row the color of first row image changes...i attached both the pics..and the php code...thanx in advance... [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/242039-problemplz-help/ Share on other sites More sharing options...
Adam Posted July 15, 2011 Share Posted July 15, 2011 An ID must be unique- only used for one element. Here you're assigning it to every image, so the browser is just applying it to the first with that ID, as it isn't expecting there to be more than one. Instead of adding a number to the end of the ID or something though, just pass the element's object to the function using the special JavaScript variable "this": <img border="0" width="20" height="20" src="enable.jpg" onclick="change(this);" /> "this" represents the current element's object; the "img" as it's represented internally within the DOM tree. Within the function add the parameter so that you can use it: function change(obj) Now instead of using getElementById(), you can simply use the variable "obj". For example: obj.src="disable.jpg"; Quote Link to comment https://forums.phpfreaks.com/topic/242039-problemplz-help/#findComment-1242995 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.