Subject: SOLUTION: javascript to “input validate” a combobox, replace a field value, save the doc, and redirect to a url?
This code is for a group calendar application and does the following:
- Provides input validation to the following fields:
EventTitle
StartDate
EndDate
If any of the fields have not been populated, a notification box appears and the cursor is placed within the field in need of a value.
- If the user has checked the StartTimeAllDay checkbox, the StartTime combobox field gets automatically assigned the earliest start time.
If the user has checked the EndTimeAllDay checkbox, the EndTime combobox field gets automatically assigned the latest end time.
-
Submits the form (or document).
-
Redirects the user automatically to the main calendar view open by month.
— BEGIN JAVASCRIPT CODE IN SUBMIT BUTTON —
sisChecked = false;
eisChecked = false;
if (form.StartTimeAllDay.checked ) {
sisChecked = true;
}
if (form.EndTimeAllDay.checked ) {
eisChecked = true;
}
if (document.forms[0].EventTitle.value==“”)
{
alert(“Please enter an event title.”);
document.forms[0].EventTitle.focus();
return false;
}
if (document.forms[0].StartDate.value==“”)
{
alert(“Please select a start date.”);
document.forms[0].StartDate.focus();
return false;
}
if (document.forms[0].StartTime.selectedIndex == 0 && ! sisChecked
) {
alert(“Please select a start time.”);
document.forms[0].StartTime.focus();
return false;
}
if (document.forms[0].EndDate.value==“”)
{
alert(“Please select an end date.”);
document.forms[0].EndDate.focus();
return false;
}
if (document.forms[0].EndTime.selectedIndex == 0 && ! eisChecked
) {
alert(“Please select an end time.”);
document.forms[0].EndTime.focus();
return false;
}
if (sisChecked)
{
document.forms[0].StartTime.selectedIndex = 1;
}
if (eisChecked)
{
document.forms[0].EndTime.selectedIndex = 26;
}
document.forms[0].submit();
— END JAVASCRIPT CODE IN SUBMIT BUTTON —
To redirect the user after form submission, I added a $$Return field with the following code:
“[http://www.domain.com” + “/” + @ReplaceSubstring(@Subset(@DbName;-1);“\”;“/”) +“/calendar?OpenView&Grid=4]”
NOTE: The beginning and ending quotation marks should be included
Hope this helps someone,
-MC