Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I am doing a HTML page where i need to remove the click attibute of some controls on another button click.


I have 5 edit buttons when i click anyone of these buttons i want to remove the "onclick" attribute of the rest. Please help me !
Posted
Comments
Arjun Menon U.K 20-Jun-12 3:16am    
var Elements = document.getElementsByName('btnEdit' + ID)
for (var i = 0; i < Elements.length; i++) {
if (Elements[i].substring(8,Elements[i].length) == ID) {
var method = Elements[i].getAttribute('onclick');
if (method != null && method != '') {
document.getElementById('btnEdit' + ID).style.display = "none";
Elements[i].removeAttribute('onclick');
}
}
}

This is the current function i am using , but the substring part returns an error
Sandeep Mewara 20-Jun-12 8:08am    
What error?

You sure you extracted the ID correctly for comparison?
Arjun Menon U.K 20-Jun-12 8:33am    
Sandeep i took Elements[i].substr instead i should have taken Elements[i].id.substr(so and so)
Sergey Alexandrovich Kryukov 3-Apr-13 0:08am    
Please stop your abuse. Let me tell you that you already got a number of abuse reports for your fake "answers", even before I noticed it.

Please stop posting non-answers as "solution". It can give you abuse reports which eventually may lead to cancellation of your CodeProject membership. And the fact you even self-accepted on formally is just outrageous, a sure way for a ban. I hope you won't do it after this warning.

Comment on any posts, reply to available comments, or use "Improve question" (above).
Also, keep in mind that members only get notifications on the post sent in reply to there posts.

—SA

Write in all button click event
CSS
document.getElementsByName("myButton")[0].disabled = true;

Where muButton is the button id.
For button 1 write the above line for rest 4 button than if u click button 1 than rest buttons will disabled.
 
Share this answer
 
Comments
Arjun Menon U.K 20-Jun-12 3:37am    
The Problem is the name of button changes... The Common part is btnEdit,after that i am appending an ID as given above(document.getElementsByName('btnEdit' + ID))
bhagirathimfs 20-Jun-12 3:53am    
document.getElementsByName("btnEdit" + ID).Disabled = true
is the above line not working???
Elsalmo 3alikom wa ra7mt ALLAH,

Dear,

If you work with HTML button then,
Give all Button same class,
HTML
<button class="edit" onclick="yourFunction();"></button>

then you have to add this function
JavaScript
function yourFunction()
{
  $('.edit').attr('onclick',null);
}

this function will remove all onclick attribute from all button with class='edit'
even your clicked button.

if you want to don't remove onclick from the trigger button, Let me know and I will handle this for you.

Best Regards
Ahmed Assaf
eBusiness Developer
 
Share this answer
 
After clicking on any button make other buttons disabled
JavaScript
document.getElementById("xx").disabled = true;
 
Share this answer
 
Comments
Arjun Menon U.K 20-Jun-12 3:44am    
The Problem is the name and id of button changes... The Common part is btnEdit,after that i am appending an ID as given above(document.getElementsByName('btnEdit' + ID))
XML
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ControlVisibilityClientSide.aspx.cs" Inherits="ControlVisibilityClientSide" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>ControlVisibilityClientSide</title>
    <script type="text/javascript">
    function toggleVisibility(controlId)
    {
    var control = document.getElementById(controlId);
    if(control.style.visibility == "visible" || control.style.visibility == "")
    control.style.visibility = "hidden";
    else
    control.style.visibility = "visible";
    }
    </script>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    <input type="button" ID="btnShowHide" value="Show/Hide" onclick="toggleVisibility('TextBox1');" /></div>
    </form>
    </body>
    </html>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900