Click here to Skip to main content
15,891,903 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a form that has a submit button in it somewhere.

However, I would like to somehow 'catch' the submit event and prevent it from occurring.

but preventDefault not working

What I have tried:

<form id="frm" method="post" action="do.php">

<table class="table table-bordered">

<tr>

<td>Name</td>
<td>Image</td>
<td>Marrird</td>
<td>Delete</td>
</tr>
<?php

while ($row = mysqli_fetch_array($data)) {
    ?>
<tr>

<td><?php echo $row['name']; ?></td>
<td><img src="<?php echo $row['image']; ?>" alt="" width="80px"></td>
<td>
<label class="switch">
<input type="checkbox" id="<?php echo $row['id']; ?>"
 class="active"  
 <?php echo $row['married'] == 1 ? 'checked' : null; ?>>
<span class="slider round"></span>
</label></td>

<td><input type="checkbox" id="<?php echo $row['id']; ?>"></td>
</tr>
  <?php
}

?>
<tr><td><input type="text" ></td>
<td><input type="file" id="file"></td>
<td><label class="switch">
<input type="checkbox" id="<?php echo $row['id']; ?>"
 class="active"  
>
<span class="slider round"></span>
</label></td></td>
<td><input type="submit" id="add"></tr>
</table>


</form>
</body>
</html>


<script>

$(function(){
	var status="";
	var id="";
	$('.active').on('click',function(){

	 id=$(this).attr("id");
     status=$(this).is(':checked')?'1':'0';
	 
	})



	$(document).on('submit','#frm',function(e)){
		e.preventDefault();
	}


})

</script>
Posted
Updated 31-Oct-18 16:40pm
v2

1 solution

I think the correct syntax should be:
JavaScript
$( "#frm" ).submit(function( event ) {
  alert( "Handler for .submit() called." );
  event.preventDefault();
});


.submit() | jQuery API Documentation[^]
 
Share this answer
 
Comments
Member 3722539 1-Nov-18 13:36pm    
thank you...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900