2017-01-03 8 views
-1

テキストフィールドが空で警告が来たら、jQuery検証フォームを作成する必要があります。jQueryで検証フォームを作成する方法は?

これは私のコードです:

<form action="" method="POST"> 
    <input type="checkbox" name="dropshiper_ceck" id="id_dropshiper_ceck"> 
    <label><b><?php echo $text_dropship; ?></b></label> 
    <div class="" id="id_dropshiper_form" name="dropshiper_form"> 
     <hr/> 
     <p> 
      <?php echo $text_dropship_name; ?> 
     </p> 
     <input type="text" name="nama_dropshiper" style="width: 97%" placeholder="<?php echo $text_add_name_dropshiper; ?>" id="id_nama_dropshiper" value=""> 
     <br/> 
     <br/> 
     <p> 
      <?php echo $text_dropship_telp; ?> 
     </p> 
     <input type="text" name="nomor_telp" style="width: 97%" placeholder="<?php echo $text_add_number_phone_dropshiper; ?>" id="id_nomor_telepon_dropshiper" value=""> 
    </div> 
</form> 
+0

この参照 - http://stackoverflow.com/questions/12437339/how-to-check-if-the-any-of-my-textbox-is-empty-or-not-in-javascript –

+0

可能な重複[jQueryを使用して入力が空であるかどうかをチェックする](http://stackoverflow.com/questions/1854556/check-if-inputs-are-empty-using-jquery) – Darshak

答えて

0
$('#id_dropshiper_ceck').change(function(){ 

    // Check the textbox when the checkbox is checked 
    if ($('#id_dropshiper_ceck').prop('checked') == true){ 
     if ($('#id_nama_dropshiper').val() == ""){ 
      // alert message 
     alert('Warning Message'); 
     } 
     if ($('#id_nomor_telepon_dropshiper').val() == ""){ 
      // alert message 
     alert('Warning Message'); 
     } 
    } 
}) 

私はあなたがチェックボックスがクリックされたときにテキストボックスをチェックしたいと思います。

関連する問題