4

I have the following Javascript code embedded in my side row

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

if(document.getElementsByName('edit')[1]!=null){
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!!!

9
  • Is there a reason you're not just removing the edit button from the page layout?
    – Matt Lacey
    Commented Dec 20, 2012 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
    Commented Dec 20, 2012 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/…. Commented Dec 20, 2012 at 2:52
  • 1
    daniel let me find out if its ok to lock record. sounds nice to do it tht simple,
    – Rao
    Commented Dec 20, 2012 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 Commented Dec 20, 2012 at 9:59

1 Answer 1

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .