2016-02-04 66 views
1

我試圖讓選定的下拉列表printerType在未選擇打印機類型值時提醒用戶,但只有當用戶選擇請求時,printertype框出現。我遇到的問題是它不會提醒用戶它沒有填充。其他人工作正常。我希望這是理解可能有點混亂。 JavaScript代碼位於底部。使用onchange時獲取輔助下拉驗證的問題

<!doctype html> 
    <html lang="en"> 
    <head> 
     <meta charset="utf-8"> 
     <meta http-equiv="X-UA-Compatible" content="IE=edge"> 
     <meta name="viewport" content="width=device-width, initial-scale=1"> 
     <title>Systems Request</title> 
    <!--bootstrap--> 
     <link href="Assets/css/bootstrap.css" rel="stylesheet"> 
       <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> 
     <!-- WARNING: Respond.js doesn't work if you view the page via file:// --> 
     <!--[if lt IE 9]> 
      <script src="../Assets/javascript/html5shiv.min.js"></script> 
      <script src="../Assets/javascript/respond.min.js"></script> 
     <![endif]--> 
      <!--custom css--> 
      <link rel="stylesheet" type="text/css" media="all" href="Assets/css/style.css"> 
    <link rel="stylesheet" type="text/css" media="all" href="Assets/css/responsive.css"> 
      <script src="Assets/Javascript/jquery-1.11.1.min.js" type= 
      "text/javascript"></script> 
     <!-- Include all compiled plugins (below), or include individual files as needed --> 
      <script src="Assets/javascript/bootstrap.js"></script> 
      <script src="Assets/Javascript/textboxname_autocomplete.js" type= 
      "text/javascript"></script> 

      <style type="text/css"> 

    .dropdown{ 
     width: 292px; 
     height: 45px; 
     font-size: 16px; 
     margin-left: 30px; 
     margin-bottom: 10px; 
     background-color: pink; 
    } 
      </style> 
    </head> 


    <body style="background-image: url('../Systems/Assets/images/background.jpg')"> 
    <?php include("includes/createHeader.php");?> 
     <section id="container"> 

     <h2>Systems Request</h2> 
     <form name="systems" id="systems-form" action="Pages/InsertProcess.php" method="post"onsubmit="return formCheck(this);"> 
     <div id="wrapping" class="clearfix"> 
      <section id="aligned"> 
      <label class="label">LanID</label><br><br> 
      <input type="text" name="lanId" id="lanId" autocomplete="off" tabindex="1" class="txtinput" > 

      <label class="label">Employee Name</label><br><br> 
      <input type="text" name="name" id="name" autocomplete="off" tabindex="1" class="txtinput"> 

      <!--manager access db list info located in the includes folder--> 
      <label class="label">Manager</label><br><br> 
      <?php include("includes/accessDB_ManagerData.php");?> 

      <!--department dropdownlist located in the includes folder--> 
      <label class="label">Department</label><br><br> 
      <?php include("includes/departmentDropdownList.php");?> 

      <!--Request Issue list info located in the includes folder--> 
      <label class="label">Request Issue</label><br><br> 

    <!-- #start of Request Issues--> 

    *<select name ="request" id="request" onchange="if (this.selectedIndex==3){this.form['printerType'].style.visibility='visible'}else {this.form['printerType'].style.visibility='hidden'};"> 
    <option value =""><?php echo '&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;Select Request Issue...'?></option> 
    <option value ="RESET CASE"><?php echo '&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;Reset Case'?></option> 
    <option value ="RESET WM PASSWORD"><?php echo "&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;RESET WM PASSWORD"?></option> 
    <option value ="REPLACE TONER"><?php echo "&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;REPLACE TONER"?></option> 
    <option value ="FIX PRINTER"><?php echo "&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;FIX PRINTER"?></option> 
    <option value ="FIX DEVICES"><?php echo "&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;FIX DEVICE"?></option> 
    <option value ="SAFETY HIGH REQUEST"><?php echo "&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;SAFETY HIGH REQUEST"?></option> 
    <option value ="OTHER"><?php echo "&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;OTHER"?></option> 
    </select><br> 
    <!-- #end of Request Issues-->* 

    ***<select class="dropdown" style="visibility:hidden;" name="printerType" id="printerType" > 
    <option Value="">Please select Printer Type</option> 
    <option Value="FS 4200DN">Kyocera FS4200DN</option> 
    <option Value="FS 3040MFP">Kyocera FS3040MFP</option> 
    <option Value="Kyocera ">Kyocera FS1370DN </option> 
    <option Value="OKI MPS710C">OKI MPS710C</option> 
    <option Value="OKI MPS711C">OKI MPS711C</option> 
    <option Value="Sharp MX450N">Sharp MX450N</option> 
    </select>*** 
    <br/> 
     <label class="label">Request Description </label><br><br> 
      <textarea name="request_comments" id="message" placeholder="Enter Description of Issue" tabindex="5" class="txtblock"></textarea> 


      <input type="submit" name="submit" id="submitbtn" class="btn btn-primary btn" tabindex="7" value="Submit"> 
      <br style="clear:both;"> 
      <?php #Hidden inputs for Status, tech comments, tech completed, tech completed date?> 
        <input name="status" type="hidden" value="RECEIVED"> 
        <input name="comments" type="hidden" value="No Comment "> 
        <input name="compUser" type="hidden" value="Unassigned"> 
        <input name="compDt" type="hidden" value="Not Completed"> 

      </section> 
      </section> 
     </div> 
     </form> 
     </section> 
    <?php include("includes/footer.php");?> 
    <script src="Assets/Javascript/gen_validatorv4.js" type="text/javascript"></script> 
    </head> 
    <script type="text/javascript"> 
    var frmvalidator = new Validator("systems"); 

    if (document.getElementById('request').selectedIndex==3){ 
    frmvalidator.addValidation("printerType","req","Please enter Printer Type"); 
    } 

    else{ 

    frmvalidator.addValidation("lanId","req","Please enter LanID"); 

    frmvalidator.addValidation("request_comments","req","Please enter request comments"); 
    } 
    </script> 
    </body> 
    </html> 

回答

0

我不得不改變一些東西,比如getElementbByName getElementById。還添加了一個名爲updateValidation的函數,將其添加到所選框的onchange部分,並將frmvalidator.clearAllValidations();添加到函數中,並將其他兩個文本框lanId和request_comments添加到if語句中。

<select name ="request" id="request" onchange=" if (this.selectedIndex==3){this.form.printerType.style.visibility='visible'} else {this.form.printerType.style.visibility='hidden'};updateValidation()"> 


<script type="text/javascript"> 
    function updateValidation(){ 
     frmvalidator.clearAllValidations(); 

    if (document.getElementById('request').selectedIndex==3){ 

    frmvalidator.addValidation("lanId","req","Please enter LanID"); 
    frmvalidator.addValidation("printerType","req","Please enter Printer Type"); 
    frmvalidator.addValidation("request_comments","req","Please enter request comments"); 

    } 

    else{ 

    frmvalidator.addValidation("lanId","req","Please enter LanID"); 

    frmvalidator.addValidation("request_comments","req","Please enter request comments"); 
    } 
    } 
    </script>