i.one i.one - 2 months ago 14
jQuery Question

jquery validation condition prevent submit

how to create jquery for prevent form submit if status=1(from database)
can't submit else can submit,where status i get from database.i'm so confused?



<form class="form-horizontal" id="myAnchor" method="post" action="<?php echo base_url(); ?>actrecord/add/<?php echo $data[0]->activity_id;?>">







<th><button onclick="warning()" type="submit" class="btn blue">new activity</button></th>







<script>
document.getElementById("myAnchor").addEventListener("click", function(event){
event.preventDefault()
});
</script>

<script>function warning(){ alert("selesaikan dulu aktiiftas sebelumnya");} </script>




Answer

Add an onsubmit trigger in your form:

<form method='POST' action='blah' onsubmit='return check()'>

Then, in javascript with jquery:

<script>
function check()
{
   $.ajax({
      url:checkStatus.php,
      success:function(data){
           return (data==1)? false : true;
      }
   });
}
</script>

Just make sure checkStatus.php will echo the status from the db.

Comments