Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>OK, ignoring the fact that inline event handlers are generally frowned upon these days, try something like the following, in which the <code>onclick</code> and <code>onfocus</code> in your HTML pass <code>this</code> through to the associated functions such that those functions have a reference to the element that the event was triggered on so that they can figure out what the related field or label is:</p> <pre><code>&lt;script&gt; function LabelOnClick(el) { var associatedFieldId = el.getAttribute("for"); if (associatedFieldId) document.getElementById(associatedFieldId).focus(); } function FieldOnFocus(el) { document.getElementById(el.id + "Label").className='FieldFocus'; } &lt;/script&gt; &lt;label id="FirstNameLabel" for="FirstName" class="FieldBlur" onclick="LabelOnClick(this)"&gt;First Name &lt;/label&gt; &lt;input id="FirstName" ... onfocus="FieldOnFocus(this)" ... /&gt; </code></pre> <p>I'll leave doing something similar for the other events as an exercise for the reader...</p> <p><strong>EDIT to match your updated question:</strong></p> <p>If this:</p> <pre><code>document.getElementById(el.id + 'Label').innerHTML='Original Value'; </code></pre> <p>is the part you're talking about where you want to replace <code>'Original Value'</code> with the elements ID with spaces added then at that point <code>el.id</code> holds "LastName" so if you use a regex like in the following line you should get "Last Name":</p> <pre><code>document.getElementById(el.id + 'Label').innerHTML = el.id.replace(/([^A-Z])([A-Z])/g, "$1 $2"); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload