My SharePoint 2010 list has a choice column that with checkboxes and allows multiple selections. For all these checkbox field choices there is a corresponding textbox fields are created. This textbox field is of type SPNumberField.

I want to validate these textboxes whenever user makes a check in the checkbox for null values.

I mean, assuming if the choice field values are:

  • MS
  • IBM
  • SAP

and its corresponding textbox fields are "MS", "IBM" ...

If a user selects IBM and if the "IBM textbox" is empty, the user should not be able to save the form.

I tried using the spUtility and pure JavaScript, but it validates only for one checkbox which is selected by default, when the mycustomnewform.aspx is loaded.

When I selected other checkboxes and click the save button, the code is not getting executed. my below code:

 var compStatusChoiceField = SPUtility.GetSPField('Company');
 var compStatusChoiceFieldValue = compStatusChoiceField.GetValue();
 alert(compStatusChoiceFieldValue + '  == is the company value');
 var varIBM = SPUtility.GetSPField('IBM').GetValue();

 if(compStatusChoiceFieldValue == 'IBM')
     if(varIBM == null || varIBM.length === 0)
        flagGeneric = false;
        alert('IBM txtbox value is a mandatory!');

1 Answer 1


You may use a simple JavaScript to find whether the checkbox is checked, if yes, find the corresponding textbox and check if the textbox contains any value. Show an alert message to the users if there is no value.

Given below a sample JS code, modify the code based on your HTML format

<script type="text/javascript" language="javascript">
function PreSaveAction() {
var isValid="";

if(document.getElementById("#CheckBox1ID").checked == true)
var validationa = $('#TextBoxForCheckBox1ID').val();
isValid += "CheckBox1";
if(document.getElementById("#CheckBox2ID").checked == true)
var validationb = $('#TextBoxForCheckBox2ID').val();
isValid += "CheckBox2";
if(document.getElementById("#CheckBox3ID").checked == true)
var validationc = $('#TextBoxForCheckBox3ID').val();
isValid += "CheckBox3";

alert("This textbox corresponding to selected checkbox cannot be empty");
return false;

return true;
  • Nagarajan, I already did the same , but its working for only ONE choice field. When I select multiselect check boxes and tried for the validation , it failed to validate other text boxes.I added the code, that I tried.Can you tell,how to get the ID of the ChoiceField? I do not want to take the ID which is generated at the viewsource or F12 Developer Tools as hardcoding that ID is not a recommended practice.
    – samolpp2
    Commented Oct 16, 2015 at 9:20
  • Try using the updated code Commented Oct 16, 2015 at 10:11
  • Can you tell, how can I get the #CheckBox1ID ?
    – samolpp2
    Commented Oct 16, 2015 at 10:25
  • You can get it from your HTML content. Else, provide the html content of table where checkboxes and textbox are present. Commented Oct 16, 2015 at 10:34
  • geekswithblogs.net/SoYouKnow/archive/2011/08/20/… this is helping me!
    – samolpp2
    Commented Oct 17, 2015 at 13:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.