title: How to get a reference to form elements in a Jenkins jelly script for a Builder configuration when the form loads?
body: <p>I am writing a Jenkins Builder, and in the jelly script for its configuration in the build configuration page I have some Javascript that I want to run when the form is loaded, to do a server lookup and get some information to help the user out with their configuration, which will also be performed when the user changes the form's values.</p>
  
  <p>Previously I have got references to the form elements by passing <code>this</code> in to functions in <code>onchange</code> or <code>onkeyup</code> attributes. However, now I want to run some script even when the form hasn't changed.</p>
  
  <p>I know I could set ID attributes on the form elements, however that's not going to work if the users add to a build two build steps both using this builder.</p>
  
  <p>I've tried generating a random ID on my builder class, and then use that to construct IDs for the elements and write that into some Javascript in the jelly file so I can find those elements there, but that doesn't get initialised until the user saves, so it won't work if the user adds two instances of this builder without saving the job:</p>
  
  <pre><code>&lt;j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form"&gt;
    &lt;f:entry title="Entry 1"&gt;
      &lt;f:textbox field="field1" id="${instance.id}-field1" onchange="fieldChanged('${instance.id}-field1')"/&gt;
    &lt;/f:entry&gt;
    &lt;script type="text/javascript"&gt;
      function fieldChanged(elementId) {
        ...
      }
  
      fieldChanged('${instance.id}-field1');
    &lt;/script&gt;
  &lt;/j:jelly&gt;
  </code></pre>
  
  <p>Are there any conventions on how to do this sort of thing? Anything built in to Jenkins/jelly to support multiple instances of the same jelly file being able to refer to their own elements?</p>