Issues with Select Box default value/mandatory attribute

craigzeleznick
Kilo Contributor

I currently have a select box and for the default value I have it as "-- Please Select --" but I also need this field to be mandatory field. When testing the red asterisk is there but if the field is left blank and the person submits the form anyway it still allows them to submit without filling in the mandatory fields.

Can someone point me in the right direction on how to fix this issue?

1 ACCEPTED SOLUTION

Hey Craig,



you can add an onSubmit client script:




function onSubmit() {  


  //Type appropriate comment here, and begin script below  


  var v = g_form.getValue('select');//the name of your field  


  if(v == '-- Please Select --') {  


  alert('You must choose an option in the select field');  


  return false;  


  }  


}



NOTE -


In place of "--Please Select --" put the value of that choice.


View solution in original post

17 REPLIES 17

"Include none" can not be used in this scenario because the user must choose either choice a or choice b. As the default choice i have an option "-- Please Select --" and if the user leaves it as that they can still submit even though the red asterisk is there.




SN.JPG


Thank you,



Craig Zeleznick


Hey Craig,



you can add an onSubmit client script:




function onSubmit() {  


  //Type appropriate comment here, and begin script below  


  var v = g_form.getValue('select');//the name of your field  


  if(v == '-- Please Select --') {  


  alert('You must choose an option in the select field');  


  return false;  


  }  


}



NOTE -


In place of "--Please Select --" put the value of that choice.


Nayan,



Someone above had said to use the same thing and i have entered the script but the user can still submit without filling in the mandatory field.



i have used the following script:



function onSubmit() {


    //Type appropriate comment here, and begin script below


      var v = g_form.getValue('null');//the name of your field


  if(v == '-- Please Select --') {//the value of the field


  alert('You must choose an option in the select field');


  return false;


  }


}



sn1.JPG


Replace if(v == '-- Please Select --')


with


if(v == 'null')



Because the value of "--Please Select--" is "null".


Should I then replace var v = g_form.getValue('null') with var v = g_form.getValue(-- Please Select --') ?



Thank you,



Craig Zeleznick