-1

I need to create jQuery validation form if text field is empty then came the warning.

This is my code:

<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>
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • refer this- http://stackoverflow.com/questions/12437339/how-to-check-if-the-any-of-my-textbox-is-empty-or-not-in-javascript – Souvik Ghosh Jan 03 '17 at 08:07
  • Possible duplicate of [Check if inputs are empty using jQuery](http://stackoverflow.com/questions/1854556/check-if-inputs-are-empty-using-jquery) – Darshak Jan 05 '17 at 11:34

1 Answers1

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');
        }
  }
})

I guess you wanna check the textbox when the checkbox is clicked.

Tim Ng
  • 1
  • 1