Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

validating select box error - assistance needed!!

Status
Not open for further replies.

cram81

Technical User
Dec 27, 2003
29
GB
hi
i can't work out why my function which checks to see if the user has selected an item from the drop down box doesn't work...

any ideas?

thanks

Code:
<html>
<HEAD>  
<script language='JavaScript'> 
 <!--  
 function changeFile(the_file) 
 { document.getElementById('thePlayer').FileName = the_file; } 
 //--> 
 </script>

 <Script Language="JavaScript"> 
 <!--  
 function testChar() { 
          var num = " .-?!abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; 
          for (var intLoop = 0; intLoop < the_form.sound_answer.value.length; intLoop++) { 
                 if (-1 == num.indexOf(the_form.sound_answer.value.charAt(intLoop))) { 
                         alert ("You have used illegal characters in the \"Sound Answer\" field \nOnly a-z (upper or lower case), space, \".\", \"?\", \"!\", \"-\" are permitted.");  
                         
                         return false; 
                 } 
          }  
   return true;
 } 

[b]function testDrop()
{
  if ((document.forms[0].elements[0].value == "Select a Sound"))
  {
    	alert("You must select a sound.");
	return false; 
  }
  return true;
}[/b]

function testEmpty()
{
if (the_form.sound_answer.value == "") 
    { 
    alert("Please complete all fields"); 
    return false;
    }
   return true;
}

function validate()
{
  var theResult = true;
  theResult = testChar() && testDrop()  && testEmpty();
  return theResult;
}

//--> 
</script>

</HEAD> 
<body><BR> 
 <h2>Playing The Object</h2> 
 <form action ='[URL unfurl="true"]http://localhost:8080/myApp/servlet/FinishReg?uID=389&picID=7'[/URL] METHOD='POST' name='the_form' onSubmit="return validate()"> 
 [b]<select name='choose_file' 
 onChange='changeFile(this.options[selectedIndex].value);'> 
 <option value='' selected>Select a Sound</option> 
<option value='c:\loop1.wav'>1</option>
 <option value='c:\loop2.wav'>2</option>
 <option value=''>6</option>
 </select>[/b]
<BR><BR><object height='8%' width='30%' id='thePlayer' classid='clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95'> 
 <param name='AutoStart' value='1' /> 
 <param name='FileName' value ='' /> 
 </object> <BR>Please enter word or phrase associated with your sound.<BR> 
<INPUT TYPE='TEXT' NAME='sound_answer'><BR><BR>
<INPUT TYPE='submit' NAME = 'submit' VALUE='submit' ></form>
<BR><BR>
</body>
<BR><BR>
</html>
 
function testDrop()
{
if ((document.forms[0].elements[0].selectedIndex == 0))
{
alert("You must select a sound.");
return false;
}
return true;
}


Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

zen.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top