Catalog Client Script - onSubmit

pushpanjalichau
Giga Contributor

I want to write an onSubmit Catalog Client Script so that out of 3 options User has to select atleast one.

If the user has not selected any option and tries to Add Item in the Cart then a message should display like "Please select atleast one accessory."

find_real_file.png

8 REPLIES 8

Sadasiva Reddy
Giga Guru

Hi Chauhan,



Write onsubmit catalog client script.



if(g_form.getValue('mouse') == ''&& g_form.getValue('keyboard') == ''&& g_form.getValue('headset') == ''){


alert('Please select atleast one accessory.');


return false;


}



Regards,


Sadasiva




Please mark helpful/ correct based on the impact


Karthik Reddy T
Kilo Sage

Hello Pushpanjali,



Please use the below script



var a = g_form.getValue('mouse');


var b = g_form.getValue(keyboard');


var c = g_form.getValue('headset');



if (a==no && b==no & c==no)


{


alert('Please select at least one accessory");


return false;


}



else


{


}


Karthik Reddy T.
ServiceNow Commnunity MVP -2018 class.

Sadasiva Reddy
Giga Guru

if 'none' is there in those options then use above script. or if the default value is 'no' then replace if(g_form.getValue('mouse') == ''&& g_form.getValue('keyboard') == ''&& g_form.getValue('headset') == '') with if(g_form.getValue('mouse') == 'no'&& g_form.getValue('keyboard') == 'no'&& g_form.getValue('headset') == 'no')



Regards,


Sadasiva




Please mark helpful/ correct based on the impact


pushpanjalichau
Giga Contributor

Hello,



I have written below script as per the suggestion.



function onSubmit() {


if(g_form.getValue('apns_mouse') == 'false' && g_form.getValue('apns_keyboard') == 'false' && g_form.getValue('apns_headset') == 'false' && g_form.getValue('docking_stations') == 'false')


  return ;


{


  //alert(g_form.getValue('contact_type'));


  //g_form.setMandatory('assigned_to', true);


  //Edited by Pushpanjali 21st July


  alert("Please select atleast one accessory");



  }


  return false;


  }



Now even after selecting one or all the accessories , the script is running and unable to Submit the requeat.


find_real_file.png