Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6776805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:04:21+00:00 2026-05-26T16:04:21+00:00

What I want to do is use the JS functions for additional input fields

  • 0

What I want to do is use the JS functions for additional input fields in the form. For instance, I want to have a LastName and LastNameLabel, etc. I am hoping I can adjust the functions in some way to find pairs Aaa and AaaLabel so that every field can have the same effect. My code is below. Thanks!

Update: I am now just trying to get the ‘Original Value’ to show the name of the element ID with a space between a lowercase letter followed by an uppercase letter. For example, if the element ID is LastName, I want the innerHTML to be “Last Name”. Thanks for all your help!!

<script type="text/javascript">
  function LabelOnClick(el) { var associatedFieldId = el.getAttribute('for');
                              if (associatedFieldId)
                                 document.getElementById(associatedFieldId).focus();
                            }
  function FieldOnFocus(el) { document.getElementById(el.id + 'Label').className='FieldFocus';
                            }
  function FieldOnKeyPress(el) { if (event.keyCode!=9 && event.keyCode!=8) { document.getElementById(el.id + 'Label').innerHTML='';
                                                                           }
                               }
  function FieldOnKeyDown(el) { el.style.width = Math.max(30,el.value.length*10)+'px';
                            }

  function FieldOnKeyUp(el) { el.value=el.value.substring(0,1).toUpperCase()+el.value.substring(1,el.value.length);
                              if (el.value=='') document.getElementById(el.id + 'Label').innerHTML='Original Value';

                            }
  function FieldOnBlur(el) { if (el.value=='') { document.getElementById(el.id + 'Label').className='FieldBlur';
                                                 document.getElementById(el.id + 'Label').innerHTML='Original Value';
                                               }
                           }
</script>

<style>
  .InputField { border: 1px dotted lightgray;
                border-bottom:1px solid black;
                min-width: 30px;
                padding: 5px;
                font-family:tahoma, arial, sans-serif;
                font-size: 14px;
  }
  .FieldBlur { color: gray;
               position: absolute;
               padding: 6px;
               padding-left: 8px;
               padding-top: 8px;
               font-family: tahoma, arial, sans-serif;
               font-size: 14px;
  }
  .FieldFocus { color: lightgray;
                position: absolute;
                padding: 6px;
                padding-left: 8px;
                padding-top: 8px;
                font-family: tahoma, arial, sans-serif;
                font-size: 14px;
  }
  .FieldInput { color: black;
                position: absolute;
                padding: 6px;
                padding-left: 8px;
                padding-top: 8px;
                font-family: tahoma, arial, sans-serif;
                font-size: 14px;
  }
</style>

<label id="FirstNameLabel" for="FirstName" class="FieldBlur"
       onclick="LabelOnClick(this)">First Name
</label>

<input id="FirstName" class="InputField" type="text" name="FirstName" maxlength="25"
       onfocus="FieldOnFocus(this)"
       onkeypress="FieldOnKeyPress(this)"
       onkeydown="FieldOnKeyDown(this)"
       onkeyup="FieldOnKeyUp(this)"
       onblur="FieldOnBlur(this)"/>

</body>

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T16:04:22+00:00Added an answer on May 26, 2026 at 4:04 pm

    OK, ignoring the fact that inline event handlers are generally frowned upon these days, try something like the following, in which the onclick and onfocus in your HTML pass this 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:

    <script>
    
    function LabelOnClick(el) {
       var associatedFieldId = el.getAttribute("for");
       if (associatedFieldId)
          document.getElementById(associatedFieldId).focus();
    }
    
    function FieldOnFocus(el) {
       document.getElementById(el.id + "Label").className='FieldFocus';
    }
    
    </script>
    
    <label id="FirstNameLabel" for="FirstName" class="FieldBlur"
           onclick="LabelOnClick(this)">First Name  </label>
    
    <input id="FirstName" ... onfocus="FieldOnFocus(this)" ... />
    

    I’ll leave doing something similar for the other events as an exercise for the reader…

    EDIT to match your updated question:

    If this:

    document.getElementById(el.id + 'Label').innerHTML='Original Value'; 
    

    is the part you’re talking about where you want to replace 'Original Value' with the elements ID with spaces added then at that point el.id holds “LastName” so if you use a regex like in the following line you should get “Last Name”:

    document.getElementById(el.id + 'Label').innerHTML
                          = el.id.replace(/([^A-Z])([A-Z])/g, "$1 $2");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know why I want to use private virtual functions, but how exactly can
I have a form where the user can dynamically add fields (clone and increasing
I want to use the functions exposed under the OpenGL extensions. I'm on Windows,
I'm using Windows XP Pro SP3. I want to use SSPI functions in my
I want to use PHP to replace javascript functions in HTML documents. For example:
I want to use a case statement in my user-defined functions because I need
I want to use min(5,10) , or Math.max(4,7) . Are there functions to this
i want to use .animate function but i have some problems i want to
I Install Apache 2.2 + PHP 5.2 and want to use any MySQL functions
I want to use this function EnumWindows(EnumWindowsProc, NULL);. The EnumWindowsProc is a Callback function:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.