2012-12-19 6 views
7

मेरे एचटीएम पेज में मैं एक बटन का उपयोग करना चाहता हूं जो फ़ंक्शन का उपयोग करके मेरा फॉर्म सबमिट करे। मैं अपने फ़ील्ड पर सत्यापन का उपयोग करता हूं और जब मैं सबमिट बटन दबाता हूं तो यह त्रुटि संदेश प्रदर्शित करता है लेकिन अंतिम रूपों को बनाए रखने के लिए यह मेरे फॉर्म को रीफ्रेश नहीं करता है। मैं बस चाहता हूं कि मेरे द्वारा दर्ज किए गए मान वहां मौजूद होंगे और केवल वह फ़ील्ड जिसमें केवल त्रुटि संदेश गायब हो जाएगा। अन्य सभी क्षेत्र वहां रहते हैं। यहाँ मेरी कोड है:अंतिम डालने वाले मानों को रीफ्रेश और बनाए रखना नहीं चाहते हैं

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html> 
    <head> 
    <!--<meta http-equiv="refresh" content="text/html; charset=iso-8859-1" />--> 
    <!-- 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> 
    --> 
    <title>Phone Registration</title> 
    <link rel="stylesheet" type="text/css" href="file:///C|/xampp/htdocs/track/css/view.css" media="all"/> 
    <script type="text/javascript" src="file:///C|/xampp/htdocs/track/javascript/view.js"></script> 
    <script type="text/javascript" src="file:///C|/xampp/htdocs/track/javascript/external.js"></script> 
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" /> 
    <script src="http://code.jquery.com/jquery-1.8.3.js"></script> 
    <script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script> 

    <script> 
     $(function() { 
      $("#datepicker").datepicker(); 
     }); 
     </script> 

    </head> 
    <body id="main_body" > 
     <img id="top" src="file:///C|/xampp/htdocs/track/images/top.png" alt=""/> 
      <div id="form_container"> 
      <h3> 
       <a href="file:///C|/xampp/htdocs/track/phonereg.php">Phone Registration</a> 
       <a href="file:///C|/xampp/htdocs/track/officerreg.php">Officer Registration</a> 
       <a href="file:///C|/xampp/htdocs/track/customerreg.php">Customer Registration</a> 
       <a href="file:///C|/xampp/htdocs/track/taskentry.php">Task Entry</a> 
      </h3>  
      <form name="order" id="form_532698" class="appnitro" method="post" action="" > 
       <div class="form_description"> 
       <h2>Phone Registration</h2> 
      </div>      
      <ul > 
       <li> 
       <span> 
       <label class="description">IMEI # : </label> 
       <input name="imei" id="imeinum" class="element text medium" type="text" maxlength="15" value=""/> 

       </span> 
       </li> 
       <li> 
       <span> 
       <label class="description" >Phone Number </label> 
       <input name="phone" id="phnum" class="element text medium" type="text" maxlength="11" value="" onblur="validate(this)"/> 

       </span> 
       </li> 
       <li> 
       <span> 
       <label class="description" >From Date </label> 
       <input id="datepicker" name="fdate" class="element text medium" maxlength="10" value="" type="text"/> 
       </span> 
       </li> 
       <li> 
       <span> 
       <label class="description" for="element_4">Active </label> 
       <input name="r1" id="rad" class="element radio" type="radio" value="Yes" checked="checked" /> 
       <label class="choice">Yes</label> 
       <input name="r1" id="rad" class="element radio" type="radio" value="No" /> 
       <label class="choice">No</label> 
       </span> 
       </li> 

       <li> 
       <input type="button" name="save" value="Save" /> 
       </li> 

       <!-- 
       <li class="buttons"> 
        <input type="hidden" name="form_id" value="532698" /> 
        <input class="button_text" type="submit" name="save" value="Save" id="" /> 
        &nbsp;<input class="button_text" type="reset" name="cancel" value="Cancel" /> 
        &nbsp;<input class="button_text" type="submit" name="search" value="Search" id="" /> 
        &nbsp;<input class="button_text" type="submit" name="up" value="Update" id="" /> 
        &nbsp;<input class="button_text" type="submit" name="del" value="Delete" id="" /> 
       </li> 
       --> 
      </ul> 
      </form> 
    </div> 
    <img id="bottom" src="file:///C|/xampp/htdocs/track/images/bottom.png" alt=""/> 

    <script type="text/javascript" language="JavaScript"> 
//submit form 
document.order.submit(); 
</script> 
    </body> 

</html> 

कृपया मुझे गाइड कैसे मैं यह कर सकता हूँ ?? मैं आभारी हो जाएगा करने के लिए आप

उत्तर

0

यदि सत्यापन विफल सर्वर से प्रविष्ट करने से प्रपत्र को रोकने के लिए इस कोड का उपयोग कर सकते हैं:

$("form").on("submit", function(event){ 
    if(!isValidForm($(this)){ 
    event.preventDefault(); 
    } 
}); 

supposingly isValidForm() विधि प्रपत्र चयनकर्ता लेता है और सच लौटाता है यदि ऐसा नहीं है, तो प्रपत्र वैध और गलत है।

0

उपयोग e.preventDefault(); या return false;

+0

और क्या आपको लगता है कि ऐसा होगा? –

+0

@VytautasButkus yup अगर आप 'वापसी झूठी' का उपयोग करते हैं, तो यह होगा? कोई संदेह नहीं मिला – Ghostman

+0

आप ओपी कैसे उस स्निपेट का उपयोग कर सकते हैं इस पर थोड़ा सा विस्तार कर सकते हैं .. –

0

सत्यापन की जाँच करें सफलता या नहीं $ में है (समारोह()) अगर फिर उस में झूठी वापस नहीं .. किसी और सच लौट ...

<script> 
$(function() { 
    $("#datepicker").datepicker(); 
    if(!validation) { 
     return false; 
    } 
    return true; 
}); 
</script> 
0

ऐसा करने के 2 प्रमुख तरीके हैं: PHP (सर्वर-साइड) और जावास्क्रिप्ट (क्लाइंट-साइड)।

पीएचपी समाधान है कि साफ नहीं है, तो आप पृष्ठ ताज़ा वहाँ मूल्यों की जाँच और हर इनपुट में सही value सेट (निकालना जिनका आप हटाना चाहते हैं)

जावास्क्रिप्ट की जरूरत है/jQuery समाधान क्लीनर है: <input type='submit' /> के बजाए एक बटन का उपयोग करें जो जावास्क्रिप्ट फ़ंक्शन को कॉल करता है, प्रत्येक इनपुट को जांचता है (यदि आपको सर्वर की जानकारी की जांच करने के लिए आप अजाक्स का उपयोग कर सकते हैं) और त्रुटियों को प्रदर्शित करता है, केवल रिक्त स्थान को गलत करने के लिए सेट करता है।

दोनों तरीके ठीक हैं, लेकिन जावास्क्रिप्ट विधि को नियंत्रित/अपडेट करने के लिए बहुत आसान है, और यह अधिक उपयोगकर्ता के अनुकूल है क्योंकि यह पृष्ठ को रीफ्रेश नहीं करता है।

संबंधित मुद्दे