Jump to content
ShidarthaRosa

How To Change A Label Via Javascript

Recommended Posts

Hello!

I am using a javascript code to change the values of some text fields everytime the user choose a value on a dropdown list at a submission form. This is the code:

<SCRIPT LANGUAGE="JavaScript">

function atualizacampos()
{
var text1 = document.getElementById('InsertRecordEntidades_Canais_Info_1');
var text2 = document.getElementById('InsertRecordEntidades_Canais_Info_2');
var text3 = document.getElementById('InsertRecordEntidades_Canais_Info_3');
var text4 = document.getElementById('InsertRecordEntidades_Canais_Info_4');
var dropC = document.getElementById('InsertRecordEntidades_Canais_ID_Canal_Doacao'); 
var Cselecionado = dropC.options[dropC.selectedIndex].text;

switch(Cselecionado) {

case 'Depósito Bancário':
text1.value='Agência'
break;
case 'Nota Fiscal':
text1.value='Número da Nota';
break;
case 'Paypal':
text1.value='Código Paypal';
break;
default:
}

}

document.getElementById('InsertRecordEntidades_Canais_ID_Canal_Doacao').onchange=atualizacampos;

</SCRIPT>

This is already working, but right now i am trying to change also the labels of those text fields.

I already tried some sibblings options, but it did not work. Can you guys please tell me the correct code to achieve that? So everytime a user change the dropdown value, the text1.value will be changed and also the label associated with this field will be changed for a new value.

 

Can someone please help?

My best regards,

Shidartha

Share this post


Link to post
Share on other sites

Good morning Sidhartha,

 

How are you?

 

I think, you can use the following code to change the text of a label on a Submission Form:

document.getElementById("InsertRecordFEILDNAME").parentNode.previousSibling.firstChild.innerHTML="NEW LABEL";

Please, enter the name of your field instead of FIELDNAME and your text instead of "new label".

 

I'll be grateful, if you tell me if the code works.

 

Have a nice day!

Share this post


Link to post
Share on other sites

Hi @ShidarthaRosa,

Just an update: Based on your workflow, you can use Virtual field as a label and set it as Calculated Value. Calculated Value form element generates dynamic calculations that automatically update as users interact with your form. Similar to Formula Fields and Calculated Fields, you can construct the calculation using functions, logic, constants, values from other fields and SQL expressions. For more information about Calculated Values, check this article: https://howto.caspio.com/datapages/datapage-components/calculated-values/

What is Virtual Field?
https://howto.caspio.com/datapages/datapage-components/virtual-fields/ 

 

Hope it helps!

Share this post


Link to post
Share on other sites

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...

×
×
  • Create New...