how to show hide info messages depending on choice value

nickyj
Tera Contributor

Hi All,

I have three choices B, C & L depending on which the user selects I like to show an info message for that choice and hide the others if the choice changes. currently only the choice L will display and if I rem out the hide fields the show fields will display when choice changes but obviously doesn't hide the other info messages.   can anyone help with this as I'm fairly new to scripting. Am I missing something obvious???

function onChange(control, oldValue, newValue, isLoading) {

if (isLoading || newValue == '')

  return;

var choiceValue = g_form.getValue('fieldname');

if (choiceValue == 'b'){

  g_form.showFieldMsg('fieldname', 'B for Broadcast', 'info');

  g_form.hideFieldMsg('fieldname', 'C for Cyclical ', 'info');

  g_form.hideFieldMsg('fieldname', 'L for Linear', 'info');

}

else

 

if (choiceValue == 'c'){

  g_form.hideFieldMsg('fieldname', 'B for Broadcast', 'info');

  g_form.showFieldMsg('fieldname', 'C for Cyclical ', 'info');

  g_form.hideFieldMsg('fieldname', 'L for Linear', 'info');

}

else

 

if (choiceValue == 'l'){

  g_form.hideFieldMsg('fieldname', 'B for Broadcast', 'info');

  g_form.hideFieldMsg('fieldname',   'C for Cyclical ', 'info');

  g_form.showFieldMsg('fieldname',   'L for Linear', 'info');

}

}

3 REPLIES 3

Chuck Tomasi
Tera Patron

Hi Nicky,



You only have to do a hideFieldMsg() once. I'd do it at the beginning to clear out any/all messages on that field. Something like this:



function onChange(control, oldValue, newValue, isLoading) {


if (isLoading || newValue == '')


  return;



var choiceValue = g_form.getValue('fieldname');


if (choiceValue == 'b'){


  g_form.hideFieldMsg('fieldname', true);


  g_form.showFieldMsg('fieldname', 'B for Broadcast', 'info');


}


else



if (choiceValue == 'c'){


  g_form.hideFieldMsg('fieldname', true);


  g_form.showFieldMsg('fieldname', 'C for Cyclical ', 'info');


}


else



if (choiceValue == 'l'){


  g_form.hideFieldMsg('fieldname', true);


  g_form.showFieldMsg('fieldname',   'L for Linear', 'info');


}


}


you star thanks very much that works a treat, I've been on that for a long time.......


Glad you like it. Don't forget to mark this as correct in case someone else is looking for a similar solution. 🙂