Skip to main content
Inspiring
May 29, 2007
Question

Validate select box or drop down

  • May 29, 2007
  • 2 replies
  • 401 views
I need scipt to validate select box or drop down for DW8 ASP or Javascript, as validate form behavior doen't do it. Thanks
This topic has been closed for replies.

2 replies

Participating Frequently
June 1, 2007
You can use this Javascript to check if any option of a select has been selected:

if (document.formname.fieldname.selectedIndex < 0) {
alert("Fieldname is required.");
return false;}
return true;

where formname is the name of the form, and fieldname is the name of the select. The alert pops up the error message, and the "return false;" prevents the form from being submitted. Put this code in a Javascript function that you call from onsubmit in the form tag, like so:

onsubmit="return functionname();"
Inspiring
May 30, 2007
It all depends upon what you want to validate. The check form from
www.yaromat.com has the option to check that the first item in a dropdown is
not selected.

--
Paul Whitham
Certified Dreamweaver MX2004 Professional
Adobe Community Expert - Dreamweaver

Valleybiz Internet Design
www.valleybiz.net

"MikeL7" <webforumsuser@macromedia.com> wrote in message
news:f3i46g$n0e$1@forums.macromedia.com...
>I need scipt to validate select box or drop down for DW8 ASP or Javascript,
>as validate form behavior doen't do it. Thanks