Jump to content

Changing labelnames by the end user


Recommended Posts

Hi Willem,

how are you? :)

Yes, it's possible to change field names depending on user's input. For example, when user enter his name, we can add his name to the label.

                label                                  value

1st field:  First Name                              John

2nd field: John, enter your last name     ______

3rd field: John, enter your age              ______

Try using the following script for this purpose:

<script>

var input = document.getElementById('InsertRecordFirstName');
var labels = document.querySelectorAll('label');

function changeLabels (){
      for (var i = 0; i < labels.length; i++) {
       labels[i].textContent = input.value + labels[i].textContent ;
      }
}

input.addEventListener('change', changeLabels);

</script>

Please replace "FirstName"  with your field name in the script.

Hope it helps!

 

 

Link to comment
Share on other sites

Hi MayMusic,

I've changed the script a little bit. Try using the following script:

<SCRIPT LANGUAGE="JavaScript">

var input = document.getElementById('InsertRecordFirst_field');
var labels = document.querySelector('label[for="InsertRecordSecond_field"]');

function changeLabels (){
     
       labels.textContent = input.value +" " +labels.textContent  ;

}

input.addEventListener('change', changeLabels);
</SCRIPT>

Please replace First_field and Second_field with your field names.

Link to comment
Share on other sites

  • 5 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...