Forum Discussion

michelle's avatar
michelle
Creator II
8 years ago

How to auto change the label color

Hi My form have Field Type: Text. Want to change label color by some condition  show user this text are required. I use java script  document.getElementById setting style ,but  need to setting "id" . I don't know how to setting "id" in aras object ? Have another better way to do required field?  

4 Replies

  • Hello Michelle, I had the same need and i solved it with a getElementsByName in Javascript: document.getElementsByName("field_name")[1]; you have to specify [1] because the fields are placed in a div with the same name so [0] is the div and [1] the field itself. Hope that i helped ! Léo
  • Hi Leo Thank you response, but I want change ItemType Property Label color. Useing "document.getElementsByName("field_name")[1]" will change  textbox word color.    
  • eli_donahue's avatar
    eli_donahue
    Community Manager
    Hi Michelle, Try this, where the highlighted value is the name of your field. var field_div = document.getElementsByName("name")[0]; var label = field_div.getElementsByClassName("sys_f_label")[0]; // some logic here to decide color label.style.color = "red"; This code gets the div that contains all of the field's components, and then retrieves the element inside that div with the class the client uses for styling labels. Eli
    Eli Donahue Aras Labs Software Engineer