Sign up ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I have the following Javascript code embedded in my side row

window.onload = new function()
function hideBtns()
document.getElementsByName('edit')[0].style.display = 'none';}

document.getElementsByName('edit')[1].style.display = 'none';}

Inspecting the edit button in chrome o/p :

<input value=" Edit " class="btn" title="Edit" name="edit" onclick="navigateToUrl('/001d000000JXhAX/e?retURL=%2F001d000000JXhAX','DETAIL','edit');" type="button">

The script is being called , though I see that the name of the "Edit" button is "edit" when I inspect it is not entering the if(document.getElementsByName('edit')[0]!=null){ block !!!

Any pointers will be a great help!!!

share|improve this question
Is there a reason you're not just removing the edit button from the page layout? – LaceySnr Dec 20 '12 at 1:10
yes i want to hide the button based on a field value!!! so this is the first part where i want to just hide the button and start putting conditions later – Rao Dec 20 '12 at 1:20
If you want don't want to have users editing a record when a field is a specific value, you could look at locking the record. Here's one way to do that:…. – Daniel Hoechst Dec 20 '12 at 2:52
daniel let me find out if its ok to lock record. sounds nice to do it tht simple, – Rao Dec 20 '12 at 3:13
This should sort you out , probably beat using a Jquery selector with document.ready(), which I tend to rely more on than window.onload – techtrekker Dec 20 '12 at 9:59

1 Answer 1

I am afraid you are likely out of luck. If you are using a Visualforce Area to place the javascript in your sidebar, Salesforce accomplishes this by placing your code in an iframe. This sandboxes the component and prevents it from accessing any other parts of the page. There is another post here detailing the changes Salesforce made to javascript in the sidebar: End of javascript sidebar workarounds?.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.