In NetSuite, ensuring that all mandatory free-form text fields are filled out correctly can be achieved through various approaches.
This post aims to provide two solutions to address this issue: an HTML5 approach and a JavaScript approach.
HTML5 Approach:
One simple way to handle mandatory fields is by utilizing an HTML5 attribute called "required."
By adding this attribute at the end of the input tag, the field is automatically set as required. Any HTML5-compliant browser will enforce this requirement.
Here's an example:
<input value="Opt-In" name="custrecord_optin" type="radio" id="custrecord_optin" class="radio1" required>
JavaScript Approach:
However, since not all users have the latest browsers with HTML5 compliance, an alternative solution using JavaScript may be necessary.
The following JavaScript code serves as a workaround for this specific problem:
function saveRecord_validation(){
var a_custRecNames = ['custrecord184', 'custrecord185', 'custrecord186', 'custrecord187', 'custrecord188'];
var s_quesNums="";
var isFormValid = true;
var isRadioChecked = false;
for (var i = 0; i < a_custRecNames.length; i++) {
var radios = document.getElementsByName(a_custRecNames[i]);
isRadioChecked = false;
for (var j = 0, length = radios.length; j < length; j++) {
if (radios[j].checked) {
isRadioChecked = true;
break;
}
}
if (!isRadioChecked) {
s_quesNums = ((i+1) < a_custRecNames.length) ? s_quesNums.concat(i+1).concat(", ") : s_quesNums.concat(i+1)+".";
isFormValid = false;
}
}
if (!isFormValid) {
alert("Please answer question(s) "+s_quesNums);
return false;
}
return true;
}
To implement the JavaScript solution in NetSuite, follow these steps:
1. Add the provided JavaScript code to the Online Form in NetSuite.
2. For further assistance, refer to NetSuite Answers: Attach Script to Form.
For guidance on creating radio buttons in NetSuite for use in online HTML forms, visit NetSuite Answers: Use Radio Button values on Online HTML forms.
By applying either the HTML5 approach or the JavaScript approach, professionals using NetSuite can ensure that mandatory free-form text fields are appropriately completed.
These solutions cater to various user scenarios and assist in maintaining accuracy and completeness in data entry.