2016-04-19 45 views
1
<html> <head> <meta http-equiv="Content-Type" content="text/html; 
charset=ISO-8859-1"> <script type="text/javascript"> function 
isDateSelected(){ 
    var today =new Date(); 
    var inputDate = new Date(document.myForm.date.value); 
    if (inputDate.value == " "){ 
     return false; 
    } else if (inputDate > today) { 
     return false; 
    } else { 
     return true; 
    } } </script> <style type="text/css"> .left { 
     float: left; 
     width: 200px; 
     text-align: center; } .right { 
     float: right; 
     width: 100px; 
     margin-top: 20px; } .center { 
     margin: auto; 
    width: 300px; } 

    .labelClass{ 
    float: left; 
    width: 150px; 
    margin-top: 20px; } .space{ padding: 0px 0px 0px 30px;} 
     .divider{ 
    width:50px; 
    height:auto; 
    display:inline-block; } .button{ position:relative; left: 0%; margin-top:10%; } 


</style> </head> <body style="background-color:#D3D3D3"> <form 
id="date" name="myForm" action="demo_form.asp" onsubmit="return 
isDateSelected();"> 

<div> <h1 style="padding: 10px; color: black; background-color: 
#D3D3D3; border: #82CAFF 2px solid"><center>Derivative Trade Report Adhoc</center></h1> </div> 

<fieldset style="height: 250px;" style="margin-top:50px;"> 
<legend>Input Details</legend> 

<table cellspacing="5" border="0" style="padding-left: 120px;"> 


<tr> 

<td> <span class="labelClass"> From Date:</span> <input type="date" 
class="labelClass" > </td> <td class="space">Clients(For other than 
Derivative Cash)</td> </tr> <tr> <td> <span class="labelClass"> 
To Date:</span> <input type="date" class="labelClass"> </td> 

<td class="space" rowspan="2"> 

<select autofocus="true" multiple="multiple" style="width: 250px;"> 
<option value="All Clients">-ALL Clients-</option> <option 
value="JHP-NAVLLP">JHP-NAVLLP</option> <option 
value="JOHAMBRO">JOHAMBRO</option> <option 
value="JOHCM">JOHCM</option> <option value="L&C">L&C</option> 
</select> </td> </tr> <tr> <td> <span class="labelClass"> TPA 
Name:</span> <input type="text" class="labelClass"> </td> </tr> <tr> 
</tr> <tr> </tr> </table> </fieldset> 

<div style="padding: 20px;text-align:center;border: #82CAFF 2px 
solid;margin-top: 5%" class="button" > <input type="submit" name="Run 
Report" value="Create Report"></input> </div> 

</form> </body> </html> </html 
+1

歡迎堆棧溢出!請閱讀[幫助中心](http://stackoverflow.com/help),特別是[我如何問一個好問題?](http://stackoverflow.com/help/how-to-ask) – evolutionxbox

+0

因爲你想要顯示警報,所以只需在函數isDateSelected()中返回false之前添加它,做好警報('日期不應該是空的')!哪裏有問題 。 – PacMan

回答

1

改變你的函數是這樣的:

isDateSelected(){ 
     var today =new Date(); 
     var inputDate = new Date(document.myForm.date.value); 
     if (inputDate.value == ""){ 
      alert("date cannot be empty"); 
      return false; 
     } else if (inputDate > today) { 
      return false; 
     } else { 
      return true; 
     } 
    } 
相關問題