Javascript validation for select box

I can't get this to work on a select box:

<script>
function validate()
{
   
  if( document.myForm.url.value == "" )
   {
     alert( "Please provide a url!" );
     document.myForm.url.focus() ;
     return false;
   }
   if( document.myForm.link_type.value == "" )
   {
     alert( "Please provide a link type!" );
     document.myForm.link_type.focus() ;
     return false;
   }
   return(true);
}
</script>

"link_type" is

<select name="link_type">
<option></option>
<option>facebook</option>
<option>myspace</option>
</select>

I've been playing around with different options, but I can't get anything to work.

Thoughts?
brucegustPHP DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Pierre CorneliusCommented:
This will not be defined: document.myForm

but this will: document.forms.myForm

change your code accordingly and try again.
0
IronhoofsCommented:
I think you are missing the value attribute on the option elements. Change your selectbox to:

<select  name="link_type">
  <option value=""></option>
  <option value="facebook">facebook</option>
  <option value="myspace">myspace</option>
</select>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
brucegustPHP DeveloperAuthor Commented:
Smell that? That's the sweet smell of resolution, folks!

Thank you so much!
0
IronhoofsCommented:
Good luck with your project!
0
Pierre CorneliusCommented:
Glad to help. Good luck.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.