function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
dfalsodfalso 

Custom Component - onLoad equivilent?

HI all,
I asked this before in another post but got no response, so I just wanted to try once more before giving up.
I'm building a custom Apex component. I need a JavaScript function to run to initialize the component features. I have an <html> section in my component, so I've tried setting the onload attribute there with no luck. I've tried puting a document.onLoad() call in both the <head> and the <body>, and also tried a window.onLoad() in both places. Nothing has worked so far.
Am I missing something, or does this just not work?

Thanks for any help anyone can provide.
TehNrdTehNrd
When you say "initialize the component features" what exactly are you initializing? Does this component use a custom controller? If so perhaps you could do some if the initializing here in the contructor.
dfalsodfalso
I am actually using a custom controller. Here's my specific scenario:

Code:
<apex:component controller="M2MManagementComponentController">
 <apex:attribute name="stringsList" id="stringsList" type="M2MStringManagement" assignTo="{!currentAssignmentLists}" description="Class that holds assigned and unassigned string lists."/>
 <html>
     <script>
   window.onLoad() = new function() {
    initializeLBContents('Select1');
   };
  </script>
  <head>
      <script>
       function initializeLBContents(lstbx)
       {
alert('inside init');
     var varBox = document.getElementById(lstbx);
     var aAssignmentArray = {!AssignedStringArray};
alert('got array');

//alert((aAssignmentArray == null — 'is null' : 'is not');
       }

   function fnMoveItems()
   {
   ...
   }
      </script>
  </head>
  <body>
   <table>
    <tr>
     <td>
      <select id="Select1" size="4"></select>
     </td>
     <td>
      <input type = "button" id = "Button1" onclick = "fnMoveItems('Select1','Select2')" value=">>"/>
      <br />
      <input type = "button" id = "Button2" onclick = "fnMoveItems('Select2','Select1')" value="<<"/>
     </td>
     <td>
      <select id="Select2" size="4"></select>    
     </td>
    </tr>
   </table>
  </body>
 </html>
</apex:component>
 
I'm basically managing a Many-to-many relationship, by putting a list of Unassigned strings in one listbox (Select1), and the currently assigned ones in the other (Select2). My input attribute is a class that has the two string arrays. So I need to initialize the two listboxes when the component is created.