2013-08-22 72 views
0

我有這段代碼,當人們離開需求字段爲空時,我想發出警告消息框。當離開字段爲空時的PHP警告消息

代碼:

if (@ is_array($cfields)) { 
    foreach ($cfields as $cf) { 
     if (intval($cf['required']) == 1) { 
      if ($cf['type'] == "text" || $cf['type'] == "textarea" || $cf['type'] == "date") { 
      ?> 
      if(!vrvar.vrcf<?php echo $cf['id']; ?>.value.match(/\S/)) { 
       document.getElementById('vrcf<?php echo $cf['id']; ?>').style.color='#ff0000'; 
       return false; 
      }else { 
       document.getElementById('vrcf<?php echo $cf['id']; ?>').style.color=''; 
      } 
      <?php 

      }elseif ($cf['type'] == "select") { 
      ?> 
      if(!vrvar.vrcf<?php echo $cf['id']; ?>.value.match(/\S/)) { 
       document.getElementById('vrcf<?php echo $cf['id']; ?>').style.color='#ff0000'; 
       return false; 
      }else { 
       document.getElementById('vrcf<?php echo $cf['id']; ?>').style.color=''; 
      } 
      <?php 

      } elseif ($cf['type'] == "checkbox") { 
       //checkbox 
      ?> 
      if(vrvar.vrcf<?php echo $cf['id']; ?>.checked) { 
       document.getElementById('vrcf<?php echo $cf['id']; ?>').style.color=''; 
      }else { 
       document.getElementById('vrcf<?php echo $cf['id']; ?>').style.color='#ff0000'; 
       return false; 
      } 
      <?php 

      } 
     } 
    } 
} 
?> 

現在它的文字變成當該字段爲空只紅色。

任何想法? :)

回答

0

添加警報這樣的消息[看到3號線]

if(!vrvar.vrcf<?php echo $cf['id']; ?>.value.match(/\S/)) { 
      document.getElementById('vrcf<?php echo $cf['id']; ?>').style.color='#ff0000'; 
      alert('Please dont leave the field blank');// I have added here 
      return false; 
      }else { 
      document.getElementById('vrcf<?php echo $cf['id']; ?>').style.color=''; 
      } 
+0

它的工作原理:d非常感謝你;) – Ernie