Client Script to check field value for Yes onSubmit

Community Alums
Not applicable

Hello All,

 

I am working on a catalog item that I need assistance with the a client script. The form has four fields where the values are Yes/No. I need to validate that are values are Yes before the form can be submitted. I think the best method is a client script but need some help with the script.

2 ACCEPTED SOLUTIONS

Harish KM
Kilo Patron
Kilo Patron

Hello you can have a onSubmit client script and check all 4 variables like below

  var demoVar = g_form.getValue('variablename');
  var demoVar1 = g_form.getValue('variablename');
  var demoVar2 = g_form.getValue('variablename');
  var demoVar3 = g_form.getValue('variablename');

  if(demoVar == 'Yes' && demoVar1 == 'Yes'  && demoVar2 == 'Yes' && demoVar3 == 'Yes')
  {
    alert("all values are yes");
    return true; //submit form
  }
  else
  {
    alert("all values need to be yes");
    return false; //abort form
  }
Regards
Harish

View solution in original post

Harish Bainsla
Kilo Patron
Kilo Patron

g_form.getValue('<name_of_the_field'>);
if(g_form.getValue('<name_of_the_field>' == "yes"));

{

return true;
}
else
{

return false;
}

 

Try to get values from all variables you want and modified code as per your requirement

View solution in original post

3 REPLIES 3

Harish KM
Kilo Patron
Kilo Patron

Hello you can have a onSubmit client script and check all 4 variables like below

  var demoVar = g_form.getValue('variablename');
  var demoVar1 = g_form.getValue('variablename');
  var demoVar2 = g_form.getValue('variablename');
  var demoVar3 = g_form.getValue('variablename');

  if(demoVar == 'Yes' && demoVar1 == 'Yes'  && demoVar2 == 'Yes' && demoVar3 == 'Yes')
  {
    alert("all values are yes");
    return true; //submit form
  }
  else
  {
    alert("all values need to be yes");
    return false; //abort form
  }
Regards
Harish

Harish Bainsla
Kilo Patron
Kilo Patron

g_form.getValue('<name_of_the_field'>);
if(g_form.getValue('<name_of_the_field>' == "yes"));

{

return true;
}
else
{

return false;
}

 

Try to get values from all variables you want and modified code as per your requirement

Community Alums
Not applicable

This worked perfectly! Thanks!!!