Form submitusing java script, form submit without submitbutton.

Form submit using javascript, jquery,registration using javascript, create registration using javascript.

 

first create a file index.html/php. and create form.</p>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Ajax Form</title>
<script type="text/javascript" src="jquery.js"/></script>
<script type="text/javascript">
$(document).ready(function () {
var flag = true;
$('.sub_btn').live('click', function () {
if ($('.fname').val() == '') {
alert('fill fname');
flag = false;
return false;
} else {
flag = true;
}
if (flag) {
$.ajax({
url: "database.php",
type: 'POST',
data: $('#ajaxform').serialize(),
success: function (data) {
//alert(data);
if ($.trim(data) == 'success') {
window.location.href = "home.php";
}else{
alert('failed');
}
}
})
}
});

});
</script>
</head>

<body>
<form method="get" id="ajaxform" >
<table width="60%" style="border:solid 1px #CCCCCC;" align="center">
<tr>
<td>First Name</td>
<td><input type="text" name="fname" class="fname"/></td>
</tr>
<tr>
<td>Last Name</td>
<td><input type="text" name="lname" /></td>
</tr>
<tr>
<td>Email</td>
<td><input type="text" name="email" /></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="pass" /></td>
</tr>
<tr>
<td>Confirm Password</td>
<td><input type="password" name="cpass" /></td>
</tr>
<tr>
<td>Address</td>
<td><textarea name="address"></textarea></td>
</tr>

<tr>
<td>
<input type="button" name="submit" class="sub_btn" value="Submit"/>
</td>
<td>&nbsp;</td>
</tr>
</table>

</form>

</body>
</html>

</div>

Now create database.php

<?php
print_r($_POST);die;
///insert query here
?>
Share Button

About admin

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Author: pramod kumar kumawat Mob: 9269727062
Free WordPress Themes - Download High-quality Templates