php - i have inserted the information in my database and also i have validate it. but if i click to insert it is redirecting to another page -
i have inserted info in database , have validate it. if click insert redirecting page. want done operation in ajax concepts please help me. in advance
html coding
<form id="myform" action="bl/checkout_report.php?action=check_out" method="post" name="myform"> <table width="200" border="0"> <h3><u><b>shipping details</b></u></h3> <tr> <th scope="row"><label>name*</label></th> <td><input id="fname" name="fname" type="text" class="shipping-required"></td> </tr> <tr> <th scope="row"><label>shipping address*</label>;</th> <td><textarea name="address" id="address" class="shipping-required"></textarea></td> </tr> <tr> <th scope="row"><label>nearest landmark*</label></th> <td><textarea name="land" id="land" class="shipping-required"></textarea></td> </tr> <tr> <th scope="row"><label>city*</label></th> <td><input id="city" name="city" type="text" class="shipping-required"></td> </tr> <tr> <th scope="row"><label>state*</label></th> <td><select id="state" name="state"> <option selected="" value="default" class="shipping- required">(please select state)</option> <option>andhara pradesh</option> <option>assam</option> <option>bihar</option> <option>delhi</option> <option>gujarat</option> <option>tamil nadu</option> </select></td> </tr> <tr> <th scope="row"><label>pin code*</label></th> <td><input id="code" name="code" type="text" class="shipping-required"></td> </tr> <tr> <th scope="row"><label>mobile number*</label></th> <td><input id="mobile1" name="mobile1" type="text" class="shipping-required"></td> </tr> <tr> <th scope="row"> <label>mail id</label></th> <td><input id="mail1" name="mail1" type="text" class="shipping-required"></td> </tr> <td><input type="hidden" id="pwd" name="pwd" value="<?php echo "$password"?>"></td> <tr> <td><input id="submit" name="submit" type="submit" value=" continue" onclick="return formvalidate()"></td> </tr> </table> </form>
javascript validate function
function formvalidate() { alert("ok"); var fname = document.myform.fname; var address = document.myform.address; var land = document.myform.land; var city = document.myform.city; var state = document.myform.state; var code = document.myform.code; var mobile1 = document.myform.mobile1; var mail1 = document.myform.mail1; if (item1(fname)) { if (idd(address)) { if (lad(land)) { if (place(city)) { if (native(state)) { if (pin(code)) { if (number(mobile1)) { if (id(mail1)) { document.myform.submit(); } } } } } } } } homecoming false; } function item1(fname) { if (fname.value != "") { var letters = /^[a-z a-z]+$/; if (fname.value.match(letters)) { homecoming true; } else { alert('nbumber'); fname.focus(); homecoming false; } } else { alert(' name should not empty'); fname.focus(); } } function idd(address) { if (address.value != "") { var letters = /^[a-za-z0-9\s,'-]*$/; if (address.value.match(letters)) { homecoming true; } else { alert('enter valid address '); address.focus(); homecoming false; } } else { alert('address should not empty'); address.focus(); } } function lad(land) { if (land.value != "") { var letters = /^[a-za-z0-9\s,'-]*$/; if (land.value.match(letters)) { homecoming true; } else { alert('enter valid land mark '); land.focus(); homecoming false; } } else { alert('land mark should not empty'); land.focus(); } } function place(city) { if (city.value != "") { var letters = /^[a-z a-z]+$/; if (city.value.match(letters)) { homecoming true; } else { alert(" city must have alphabet charater only"); city.focus(); homecoming false; } } else { alert('city should not empty'); } } function native(state) { if (state.value == "default") { alert('select state list'); state.focus(); homecoming false; } else { homecoming true; } } function pin(code) { if (code.value != "") { var uadd_len = code.value.length; if (uadd_len == 6) { homecoming true; } else { alert(" pin code must have 6 numbers"); code.focus(); homecoming false; } } else { alert('pincode should not empty'); } } function number(mobile1) { if (mobile1.value != "") { var uadd_len = mobile1.value.length; if (uadd_len == 10) { homecoming true; } else { alert('enter 10 digit mobile number '); mobile1.focus(); homecoming false; } } else { alert('mobile number should not empty'); mobile1.focus(); } } function id(mail1) { if (mail1.value != "") { var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/; if (mail1.value.match(mailformat)) { homecoming true; } else { alert('invalid mail service format '); mail.focus(); homecoming false; } } else { alert('mail should not empty'); mail1.focus(); } }
you can either write own ajax script xhr create object or utilize existing libraries jquery ease work you
http://api.jquery.com/jquery.post/
$("#foo").submit(function(event){ var request = $.ajax({ url: "/checkout_report.php", type: "post", data: serializeddata }); });
check existing ex in stackoverflow: jquery ajax post example
php javascript html mysql
No comments:
Post a Comment