+ Start a Discussion
David SDavid S 

JavaScript issue in home page component

I'm new to javascript.  I'm having trouble with the following code in a home page component.   The purpose is to disable the "All Users" list view on the Calendar page:
	function hideButton() {    
		var saveandNewid = document.getElementsByName('fcf');            
		var saveNewlen = saveandNewid.length;       
		for( var i=0; i< saveNewlen; i++)               

	window.onload = hideButton;

While the script does work, the problem is that it interferes with other standard layout pages in Salesforce, such as the related lists on a page layout stop working.  Is there anything i can do to stop this behavior.   I understand there is the noConflict function available, but no sure how i would use it in this case.

Thanks in advance,
The statement document.getElementsByName('fcf') is finding more than your button.  getElementsByName will find anything with the provided 'name' and name does not require a unique value in the DOM.

You need to uniquely identify the element you are trying to disable.  Either check for an identifying attribute in your for loop, or use a more specific selector.  Are you trying to disable the 'Multi User View' link?

User-added image

 In my org that link has style class 'multiUserViewIcon', so I'd probably use jQuery like this:

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js" />

<script type="text/javascript">

    $j = jQuery.noConflict();
    $j(document).ready(function() {

FYI, noConflict is for preventing collisions between javascript libraries, so you are correct that it won't help in this case.
David SDavid S
Thanks robdobby,
Actually, I don't want to prevent the users from going into the multi user view.  But once they are there I don't want them to select the "All Users" option in the list view.  Is it possible to just disable that option?