I have a simple js function to validate fields are not blank. It works perfectly well on normal single value fields, it pops-up an alert message and moves the cursor back to the offending field if it is blank, but on a multi-vlaue field it awlways thinks it is blank. I don’t understand javascript at all so could somoene please show me aht my function should say so that it works also on multi-value fields.
This js function is in the JS Header section…
function validate_required(field,alerttxt)
{
with (field)
{
if (value==null||value==“”)
{
alert(alerttxt);return false;
}
else
{
return true;
}
}
This js is in the onSubmit section…
if (validate_required(Test,“Please select at least one test that you would like the candidate to complete. \nHold down the Ctrl key and click additional test titles to select multiple tests.”)==false)
Subject: JS validation not working on multi value field
I think you’ll find, Chris, that it isn’t multivalue fields that are causing the problem, but radio buttons, checkboxes and has a number of elements as children, and you need to find out which of them are selected.
I posted a function here a while back called atGetField(), which you can use to get the value(s) of any sort of field. The return is an array, though, so you’d need either to check the zeroeth element of the return OR join the values:
function validate_required(field, alerttxt) {
if (atGetField(field).join(“”) == “”) {
alert(alerttxt);
return false;
}
return true;
}
That leaves you with the problem of focus. For ordinary inputs, textarea and
Subject: RE: JS validation not working on multi value field
Stan,thanks for the explanation, though I really don’t understand the resolution. The problem is that for some reason js confuses me, it might as well be Arabic, though i could probably understand that better
Subject: RE: JS validation not working on multi value field
JS is a simple enough language, Chris (even if it is a lot more powerful and expressive than most people realise). What’s missing is a clear picture of the object model you’re working with. In other words, it’s not so much JS that’s the black hole in your knowledge as it is the HTML, in much the same way as a complete knowledge of LotusScript would be the next best thing to useless if you didn’t know much about databases, views, documents and items.
Working with the simplest forms you can imagine and using the View->Source option in the browser can help you understand what’s going on. It doesn’t help that Domino can render the “same field” in so many different ways, depending on the form or subform it appears on, hide-when conditions, and so forth. That’s why I’ve abstracted away the mechanics of working with fields with functions like atGetField() and others. (As opaque as that function may appear to you, you really wouldn’t want to see the version I actually use – it uses two-letter names for everything, proxy functions for many of the more verbose common functions, and has has most of the white space stripped out, reducing the overall size of the function library by more than 70% for bandwidth reasons.)