Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to validate array input field using javascript

How to validate array input field?Please help me to solve this issue.

<form action="" method="post" name="frmPayPal1" id="frmPayPal1" onsubmit="return validateForm()"/>
 <input type='text' name='txt_jobid[]' id='txt_jobid' >
  <input type="submit" value="submit"/>
  </form>

<script>

 function validate(job)
 {
 if(job.elements['txt_jobid[]'].length == 0)
{
    alert(" Please Enter Value!");  
    return false;
}   

}
 </script>
like image 367
think_user Avatar asked Feb 12 '26 11:02

think_user


1 Answers

Maybe this...

<form action="" method="post" name="frmPayPal1" id="frmPayPal1">
    <input type="text" name="txt_jobid[]" id="txt_jobid">
    <input type="submit" value="submit">
</form>

<script>
$(document).ready(function(){
    $('#frmPayPal1').on('submit', function(){
        var lngtxt=($(this).find('input[name="txt_jobid[]"]').val()).length;
        console.log(lngtxt);
        if (lngtxt==0){
            alert('please enter value');
            return false;
        }else{
            //submit
        }

    });
});
</script>
like image 195
andrea_19920611 Avatar answered Feb 13 '26 23:02

andrea_19920611



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!