On one of my forms I have a dialog list from where the user can choose which customer they would like to use, this field has to be mandatory! Can someone help me with how I should
write the code for this, mine does not work :0(
This is my code:
¨
triggerBeforeUnload = false;
f = document.forms[0];
Customer = f.CustomerID;
if (Customer.options[selectedIndex].value == '') {
alert("You have to choose Customer!");
Customer.focus();
return false;
}
The code generates the same error message as before… Can it have something to do how I programme the dialog list? I use “Use view dialog for choises” …
It works when I test it on a html page as you suggested but not in domino designer… Maybe I put the code in the wrong place? I have placed my code in JS Header on my form. I have other fields that are just regular text fields that works just fine with that kind of validation but when it comes to the dialog box it just does not work…
The code for validating my text fields looks like this:
I think you could put the OnClick code in other events, but I’ve not tried that.
Brian
JSHeader:
function getFieldValue(field)
{
switch(field.type)
{
case "text" :
case "textarea" :
case "password" :
case "hidden" :
return field.value;
case "select-one" :
var i = field.selectedIndex;
if (i == -1) return "";
else return (field.options[i].value == "") ? field.options[i].text : field.options[i].value;
case "select-multiple" :
var allChecked = new Array();
for(i = 0; i < field.options.length; i++)
if(field.options[i].selected)
allChecked[allChecked.length] = (field.options[i].value == "") ? field.options[i].text : field.options[i].value;
return allChecked;
case "button" :
case "reset" :
case "submit" :
return "";
case "radio" :
case "checkbox" :
if (field.checked) { return field.value; } else { return ""; }
default :
if(field[0].type == "radio")
{
for (i = 0; i < field.length; i++)
if (field[i].checked)
return field[i].value;
return "";
}
else if(field[0].type == "checkbox")
{
var allChecked = new Array();
for(i = 0; i < field.length; i++)
if(field[i].checked)
allChecked[allChecked.length] = field[i].value;
return allChecked;
}
else
var str = "";
for (x in field) { str += x + "\n"; }
alert("I couldn't figure out what type this field is...\n\n" + field.name + ": ???\n\n\n" + str + "\n\nlength = " + field.length);
break;
}
return “”;
}
“OK” OnClick:
var cov = getFieldValue(document.forms[0].Value);
//the field is called “Value”, it’s a copy from something it’s a little confusing, but I’m not changing just no
{
if (cov == "") {
alert("Please select a tire")
return false
}
window.returnValue = document.forms[0].Value.options[document.forms[0].Value.selectedIndex].text;
self.close()
return true
}