Forum Moderators: open

Message Too Old, No Replies

drop down validation

         

bagheera

8:59 am on Apr 20, 2004 (gmt 0)

10+ Year Member



I have a validation function that works perfect for normal text fields, but when the field is a drop down it doesnt do anything. Im not coding JS so I might have missed something....

onsubmit="return (
validRequired(this.address, 'Address') &&
validRequired(this.name, 'Name') &&
validRequired(this.counsid, 'Counsellar)
);"

The "counsid" is a drop down field....and have no effect...the values are picked from mySQL dynamically.

my js function looks like:

function validRequired(formField, label)
{
if (formField.value == "")
{
alert('Field can not be empty: ' + label);
formField.focus();
formField.select();
return false;
}
return true;
}

thanks

korkus2000

3:49 pm on Apr 20, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In javascript you get a select box value like this:
document.form1.select1.options[document.form1.select1.selectedIndex].value

make a second function like:

function validRequired2(formField, label)
{
if (formField.options[formField.selectedIndex].value == "")
{
alert('Field can not be empty: ' + label);
return false;
}
return true;
}

I don't think you want to select or give focus to this element.

bagheera

8:28 am on Apr 21, 2004 (gmt 0)

10+ Year Member



Thanks, Ill try this out!