Hi I have a javascript problem. I have a validate script that checks if a field in a form is filled out. F.eks I have a field in a form named form1 : <input type="text" name="name">
On submit I have a js function that return true or false.
Here are parts of that one:
if (document.form1.harlengde.value == "")
{
missing += "Name";
}
if (missing != "")
{
alert(missing);
return false;
}
else return true;
But my problem comes when I have a select field that let you chooce more then one value.
<select mutiple name="hobby[]">
<option>Soccer</option>
<option>Hockey</option>
<option>Baseball</option>
</select>
I have tryed to make a funcion to make sure they select atleast one field. It goes somthing like this:
if (document.form1.hobby[0].value == "")
{
missing += "Hobby";
}
I know this it totaly wrong, but I really dont know how to fix it. I also know there is many ways to check this in php, but I need to use javascript.
Can anyone help me?
PS: There might be some typos here, but this was just an example so the problems isn't typos 🙂