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

oharel
Kilo Sage

Is the "-- Please Select --" your value, inserted manually? If it is, 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 --') {//the value of the field


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


  return false;


  }


}



harel


Edit: if this is a catalog item, then use a Catalog Client Script, not a client script.


Thank you for the quick response. After i inserted the script as a new client script i am still getting the same result.



During testing, if the field is left blank and the user submits, very quickly the blank field gets highlighted in a red box but proceeds to let the user submit the request anyway


hi Craig,



What is the name of your field?


Note that I wrote:


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


In my example, the field's name was "select". In yours, it can be "type_of_request" - according to the screenshot you posted.


And one more thing:


What is the VALUE of the choice? The field has both a value and a display for the value - what's being shown to the user. In my example, both of them were '--Please Select--' but in your case they might be different.


The code I gave you works for sure, as I created it in my own instance.


If you are not clear on what to do, can you please share:


1. your code


2. a screenshot of your field


3. a screenshot of the --Please Select-- field



harel


Thank you for taking the time to troubleshoot. Please see below.



Code:



function onSubmit() {


//Type appropriate comment here, and begin script below


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


if(v == 'null') {//the value of the field


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


return false;


}


}



Screenshot 1:





Screenshot 2:





Thank you,



Craig Zeleznick