September 02, 2010, 09:37:22 pm *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Dont forget to check the Facile Forms wiki !
 
   Home   Help Search Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: Conditional Validation [Solved]  (Read 1664 times)
david63
Freshman
*
Offline Offline

Posts: 35


« on: July 02, 2006, 05:04:28 pm »

How would I check that an item has been selected from a "Select List" only when there is an entry in a text field?
« Last Edit: July 03, 2006, 12:04:22 pm by david63 » Logged

David
Remember - You only know what you know
and - you don't know what you don't know!
boldee
Administrator
Living Legend
*****
Offline Offline

Posts: 1359



« Reply #1 on: July 02, 2006, 05:29:05 pm »

Place in your select list custom validation script and type a message in the message field, you can see this in the embedded php example in the samples package.
Code:
function ff_your_selectlist_name_validation(element, message)
{
    if (element.value=='none' || element.value=='') {
        ff_validationFocus(element.name);
        return message;
    } // if
    return '';
} // ff_your_selectlist_name_validation
Logged

Nick

Please read the forum rules first!
Please do not use PM for generic questions!
Please visit...
Protean MMO
david63
Freshman
*
Offline Offline

Posts: 35


« Reply #2 on: July 03, 2006, 09:35:20 am »

Thanks boldee

If I am reading your code correctly then that is validating that there is an item selected from the list. That part I can do - but what I need is to only perform that validation if there is an entry in a text field.

For example I have an optional text field called height in which the user will enter a value and next to that I have a Select List with three values (none, feet, meters) and I need to ensure that when there is an entry in the text fiels then a selection is made from the list.
Logged

David
Remember - You only know what you know
and - you don't know what you don't know!
boldee
Administrator
Living Legend
*****
Offline Offline

Posts: 1359



« Reply #3 on: July 03, 2006, 10:29:10 am »

Ok why not look at the country select example and see if you can work a solution from that, alternatively you could validate from the select list by changing the element.name's to getElementByName('your text field').value; so that the select list validates the textfield. Ive not tested this so not sure if it works but worth a try  Smiley

Somthing like....
Code:
function ff_your_selectlist_name_validation(element, message)
{
    if (getElementByName(your text field).value=='') {
        ff_validationFocus(getElementByName('your text field').value);
        return message;
    } // if
    return '';
} // ff_your_selectlist_name_validation

I still think it would be best if the select list is not active until you type a value in the text field though.
Logged

Nick

Please read the forum rules first!
Please do not use PM for generic questions!
Please visit...
Protean MMO
david63
Freshman
*
Offline Offline

Posts: 35


« Reply #4 on: July 03, 2006, 12:04:01 pm »

Solved it by using this code
Code:
function ff_list_validation(element, message)
{
    if (ff_getElementByName('my_item').value !='') {
        if ((element.value == 'none' || (element.value == ''))) {
            if (message=='') message = element.name+" has not been selected.\n";
            ff_validationFocus(element.name);
            return message;
        }
    }
    return '';
}
« Last Edit: July 03, 2006, 12:51:18 pm by david63 » Logged

David
Remember - You only know what you know
and - you don't know what you don't know!
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by SMF © 2001-2006 Lewis Media
| Terms of Use | Privacy | Sitemap |