This topic is locked

Require one of two fields

1/17/2008 7:59:52 PM
PHPRunner General questions
C
Christopher author

I have a registration form with about 30 fields, half of which are required. Standard stuff all done with the visual editor.
I have a special section that uses a three step dependent drop down for the user to select a school. There is a possibility that their school may not be in the list, in which case I need them to enter it in a field.
My problem comes with validating that one or the other of these steps are completed. I don't know how to do an either A or B must have a value, and to further complicate things, I don't want to different kinds of validation confusing the user (the regular ones and something special for this?).
Can anybody help?

J
Jane 1/21/2008

Hi,
you can validation dynamically adding some JavaScritp code on your page on the Visual Editor tab.

Here is a sample:

{literal}<script>

document.forms.editform.value_FieldName.onchange=function()

{

if(this.options[this.selectedIndex].value=='your value')

{

define('value_FieldName','IsRequired','FieldName: ');

}

else

{

undefine('value_FieldName');

}

}
function undefine(n)

{

if (document.editform != null)

{

for (i = 0; i < checkObjects.length; i++)

{

if (checkObjects[i].form.name==n)

checkObjects.splice(i,1);

}

}

}

</script>{/literal}