2009-12-07 8 views
5

पर JQuery साफ़ फॉर्म मेरे पास नीचे JQuery संवाद स्क्रिप्ट है, मैं यह पता लगाने की कोशिश कर रहा हूं कि जब मैं संवाद बंद करता हूं तो फ़ॉर्म को साफ़ करता है।बंद करें

function clearForm() 
{ 
$(':input','#calcQuery') 
.not(':button, :submit, :reset, :hidden') 
.val(''); 
}; 
// form popup 
$(document).ready(function() 
{ 
//var dataString = $("#calcQuery").serialize(); 
    $("#formBox").dialog({ 
     bgiframe: true, 
     autoOpen: false, 
     height: 600, 
     width: 400, 
     modal: false, 
     closeOnEscape: true, 
     title: "Calculator", 
     buttons: { 
      "Calculate": function() { 

// form post 
      $.ajax({ 
      type: "POST", 
      url: "calc.php", 
      data: $("#calcQuery").serialize(), 
      dataType: "html", 
      success: function(response) 
       { 
       $("#calcBox").html(response); 
       $("#calcBox").show(); 
       }, 
      error: function 
       (xhr, ajaxOptions, thrownError) 
        { 
        alert(xhr.status); 
        alert(thrownError); 
        } 



    }).responseText; 

// form post 

       } 
      } 
    }); 

$('#calcButton').click(function(){ 
    $('#formBox').dialog('open'); 
    return false; 
    }); 

}); 

$("#formBox").bind('dialogclose', function(event) 
{ 
clearForm(); 
}); 
+0

form.reset() चाल कर सकता ... – NDM

उत्तर

3

मैं इसे का उपयोग करके काम मिल गया ...

function clearForm(form) 
{ 
    $(":input", form).each(function() 
    { 
    var type = this.type; 
    var tag = this.tagName.toLowerCase(); 
     if (type == 'text') 
     { 
     this.value = ""; 
     } 
    }); 
}; 

और .....

// form post 
      $.ajax({ 
      type: "POST", 
      url: "calc.php", 
      data: $("#calcQuery").serialize(), 
      dataType: "html", 
      success: function(response) 
       { 
       $("#calcBox").html(response); 
       $("#calcBox").show(); 
       clearForm("#calcQuery"); 
       }, 
      error: function 
       (xhr, ajaxOptions, thrownError) 
        { 
        alert(xhr.status); 
        alert(thrownError); 
        } 



    }).responseText; 

// form post 

का उपयोग करें ... अब .. मैं रेडियो बटन को "जीबी" के डिफ़ॉल्ट पर कैसे सेट करूं?

&nbsp;KB <input type="radio" name="curr_unit" value="KB" /> 
&nbsp;MB <input type="radio" name="curr_unit" value="MB" /> 
&nbsp;GB <input type="radio" name="curr_unit" value="GB" checked/> 
&nbsp;TB <input type="radio" name="curr_unit" value="TB" /> 

धन्यवाद

6

यह फार्म रीसेट हो जाएंगी:

$("#form").trigger("reset"); 
+0

आप स्पष्ट कर सकते हैं, जहां इस रेखा से जाना चाहिए। धन्यवाद। –

+0

@ फ्रैंकिसरोडर्स मेरे उत्तर को देखो –

0
`jQuery("#form").trigger("reset");` 

यह सफलता समारोह के बाद सफलता संदेश प्रदर्शित किया गया है में जगह।
फिर यह पूरी तरह से काम करता है!
उदाहरण:

... 
beforeClose: function() { 
    $("#form").trigger("reset"); 
}, 
... 

यह बचाने पर अपने प्रपत्र को रीसेट कर देगा रद्द पर और शीर्षक पट्टी बंद करें बटन पर:

success : function(){ 
jQuery('#contactsMsgs').html('<p class="success">All is well, your e&ndash;mail has been sent.</p>'); 
jQuery('#yourformname').trigger('reset'); 
spinner.hide();` 
} 
3

अधिक सुरुचिपूर्ण अपने तरीकों का एक संयोजन है। Select2 के लिए अपवाद जो मैन्युअल रूप से किया जा करने के लिए है:

$("#mySelect2").select2('data', null); 

ही BeforeClose अंदर