2013-04-10 168 views
-2

我想驗證我的表單使用JavaScript。如果沒有選擇單選按鈕,則在填充部分下方出現「您沒有選擇填充物」的文字。其餘的代碼工作正常。 cslab.bc.edu/~thomasfd/hw8/hw8.php現場觀看。驗證表單使用Javascript

 <script> 

    function validateform(){ 
      var namevalid = validatename(); 
      var entreevalid = validateentree(); 
      var fillingvalid = validatefilling(); 

      return false; 

     } 


     function displayfilling(){ 
      var fillingselected =document.forms["mytestform"].filling.value; 
      var resultloc=document.getElementById("fillingerror"); 
      resultloc.innerHTML = "You have selected " + fillingselected + "."; 
     } 

     function validatefilling(){ 
      var a=document.getElementById("myfilling"); 
      if (a.selectedIndex == 0){ 
       var resultloc=document.getElementById("fillingerror"); 
       resultloc.innerHTML = "<span style='color:red;'>Please select a filling!<span>"; 
       return false; 
      } 
      var resultloc=document.getElementById("fillingerror"); 
      resultloc.innerHTML = ""; 
      return true; 
     } 
</script> 
+0

您是否爲客戶端驗證編寫了JavaScript? – 2013-04-10 17:53:30

+2

是這個功課? – 2013-04-10 17:53:48

+1

而不是傾銷所有的代碼,爲什麼你不只是發佈的JavaScript,然後它會更容易使用來幫助你! +1 @AaronW。 – 2013-04-10 17:55:06

回答