2013-02-11 38 views
0

我已經在我的數據庫中插入了信息,我也驗證了它。但如果我點擊插入它重定向到另一個頁面。我想在AJAX概念中完成這個操作,請幫助我。由於提前我已將該信息插入到我的數據庫中,並且我已驗證它。但如果我點擊插入它重定向到另一個頁面

HTML編碼

<form id="myform" action="bl/checkout_report.php?action=check_out" method="post" name="myform"> 
    <table width="200" border="0"> 
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <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 a 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驗證功能

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(); 
       } 
       } 
      } 
      } 
     } 
     } 
    } 
    } 
    return false; 
} 

function item1(fname) { 
    if (fname.value != "") { 
    var letters = /^[A-Z a-z]+$/; 
    if (fname.value.match(letters)) { 
     return true; 
    } else { 
     alert('nbumber'); 
     fname.focus(); 
     return 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)) { 
     return true; 
    } else { 
     alert('Enter Valid Address '); 
     address.focus(); 
     return 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)) { 
     return true; 
    } else { 
     alert('Enter Valid Land Mark '); 
     land.focus(); 
     return 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)) { 
     return true; 
    } else { 
     alert(" City Must have alphabet Charater Only"); 
     city.focus(); 
     return false; 
    } 
    } else { 
    alert('city should not empty'); 
    } 
} 

function native(state) { 
    if (state.value == "Default") { 
    alert('Select your State from the list'); 
    state.focus(); 
    return false; 
    } else { 
    return true; 
    } 
} 

function pin(code) { 
    if (code.value != "") { 
    var uadd_len = code.value.length; 
    if (uadd_len == 6) { 
     return true; 
    } else { 
     alert(" Pin Code Must Have six Numbers"); 
     code.focus(); 
     return false; 
    } 
    } else { 
    alert('Pincode should not empty'); 
    } 
} 

function number(mobile1) { 
    if (mobile1.value != "") { 
    var uadd_len = mobile1.value.length; 
    if (uadd_len == 10) { 
     return true; 
    } else { 
     alert('Enter 10 Digit Mobile Number '); 
     mobile1.focus(); 
     return 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)) { 
     return true; 
    } else { 
     alert('Invalid Mail Format '); 
     mail.focus(); 
     return false; 
    } 
    } else { 
    alert('Mail should not empty'); 
    mail1.focus(); 
    } 
} 
+2

是的,也許你可以只發布了相關的代碼。沒有人會通過250行隨機代碼來試圖破譯你想要的。 – Mike 2013-02-11 04:59:48

+0

你已經給出了巨大的代碼,但沒有明確你需要什麼。 – Chella 2013-02-11 05:00:40

+0

我認爲你錯誤的驗證檢查返回..一次檢查你的代碼.. – sasi 2013-02-11 05:02:32

回答

1

你有沒有嘗試過的jQuery submit

(function($) 
{ 
    $('#form').submit(function() 
    { 
     //check for validation.. 
     return false; 
    }); 
});

如果你不想使用jQuery,那麼你應該嘗試http://www.simonerodriguez.com/ajax-form-submit-example/

+0

爲什麼jQuery?它看起來像OP已經寫了一切在普通的JS。 – Mike 2013-02-11 05:03:13

0

您可以使用jquery form plugin。 這個插件也可以幫助你上傳文件。 所以我認爲這是最適合你

下面是這個插件http://malsup.com/jquery/form/

和例子在這裏文檔http://malsup.com/jquery/form/#ajaxForm

你的功能formValidate是非常複雜的嘗試寫這樣簡單的方式對EGS:

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; 
    var status=true; 
    if(!item1(fname)) 
    { 
     status=false; 
    } 
    if(!idd(address)) 
    { 
     status=false; 
    } 
    if(!lad(land)) 
    { 
     status=false; 
    } 
    if(!place(city)) 
    { 
     status=false; 
    } 
    if(!native(state)) 
    { 
     status=false; 
    } 
    if(!pin(code)) 
    { 
     status=false; 
    } 
    if(!number(mobile1)) 
    { 
     status=false; 
    } 
    if(!id(mail1)) 
    {       
     status=false; 
    } 
    //thinking all functions return true or false 
    if(status) 
     document.myform.submit(); 
    return status; 
} 
相關問題