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!!!

  • Is there a reason you're not just removing the edit button from the page layout? – Matt Lacey 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
  • 3
    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: verticalcode.wordpress.com/2012/07/26/…. – Daniel Hoechst Dec 20 '12 at 2:52
  • 1
    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
  • 3
    This should sort you out , probably beat using a Jquery selector with document.ready(), which I tend to rely more on than window.onload tehnrd.com/show-and-hide-buttons-on-page-layouts – techtrekker Dec 20 '12 at 9:59

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?.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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