提示:上面内容有点失误:select应该和下面的select5对应

解决方案 »

  1.   

    <select name="select5" id="select5">
    if(document.form1.select5.options[document.form1.select5.selectedIndex].value=="")
    alert()
      

  2.   

    if(document.form1.select5.options(document.form1.select5.selectedIndex).value=="")
    alert("不能为空")
      

  3.   

    有关必须输入验证,俺已经写好了一个通用的,不知是否符合楼主意思:
    <html><head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>New Page 1</title>
    </head><body>
    <form name=aaa>
    StudentName1:<input altStr="StudentName1" >*<br/>
    StudentName2:<input altStr="StudentName2" >*<br/>
    StudentName3:<input altStr="StudentName3" >*<br/>
    StudentName4:<input ><br/>
    <input type=button value=checkAllNecessaryInputs onclick="checkAllNecessaryInputs(document.forms['aaa']);">checkAllNecessaryInputs(formObj)<br/>
    </form></body></html>
    <script>
    /**
    * This function is to get if all necessary inputs have been inputted.
    * Please give the NecessaryInput a property named "altStr".This property will be alert when it has not been inputed.
    * For Example, 
    *   This is a necessary input:<input altStr="Name">
    *   This is not a necessary input:<input altStr="Name">
    * JK 2003-12-08
    */
    function checkAllNecessaryInputs(formObj)
    {
    if(formObj==null) formObj=document.forms[0];
    var theFirstNecessaryInputToBeFilled=null;//Get it to focus;
    var theAlertStr="";
    var theNumOfInputsToBeFilled=0;

    var theElementsOfTheForm=formObj.elements;
    for (var i=0;i<theElementsOfTheForm.length;i++)
    {
    if(theNumOfInputsToBeFilled>9) break;
    if((theElementsOfTheForm[i].altStr!=null)
    &&(theElementsOfTheForm[i].altStr!="")
    &&(theElementsOfTheForm[i].value=="")
    )
    {
    theNumOfInputsToBeFilled++;
    theAlertStr=theAlertStr+"\n"+theElementsOfTheForm[i].altStr;
    if(theFirstNecessaryInputToBeFilled==null)
    theFirstNecessaryInputToBeFilled=theElementsOfTheForm[i];
    }
    }
    if(theNumOfInputsToBeFilled>0)
    {
    alert("Please input :"+ theAlertStr);
    theFirstNecessaryInputToBeFilled.focus();
    return false;
    }
    return true;
    }</script>