www.webdeveloper.com
Results 1 to 3 of 3

Thread: [RESOLVED] Cancelling default form action & clearing text fields

  1. #1
    Join Date
    Jan 2009
    Posts
    53

    resolved [RESOLVED] Cancelling default form action & clearing text fields

    I have a form with 3 text fields. When the form is submitted a js function is called. This function retrieves the field values, stores them, and sends them to a php page. Right before sending the values to the php page, the form is hidden. The default action of the form is canceled. A callback function later re-displays the form and clears the text field values, via setting the value properties to "".

    Currently, the form submits and hides correctly, but when re-displayed text fields retain their values rather then being cleared. Below is my code, help resolving this problem is appreciated. Thanks.

    Code:
    ajax function(){...
    var msgForm = document.getElementById("msgForm");
    msgForm.style.display = "none";
    ...}
    
    function sendMsgCallback(ajaxResponse){
    	if (ajaxResponse.match(/sent/i)){
    	alert("send successful!");
    	var msgForm = document.getElementById("msgForm");
    	var progressImg = document.getElementById("progressImg");
    	progressImg.parentNode.removeChild(progressImg);
    	msgForm.style.display = "block";
    	msgForm.getElementById("msgRecipient").value = "";
    	msgForm.getElementById("msgSubject").value = "";
    	msgForm.getElementById("msgContent").value = "";
    	} else {
    		alert(ajaxResponse)
    	}
    } // end sendMsgCallback

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Code:
    function sendMsgCallback(ajaxResponse){
    	if (ajaxResponse.match(/sent/i)){
    	alert("send successful!");
    	var msgForm = document.getElementById("msgForm");
    	var progressImg = document.getElementById("progressImg");
    	progressImg.parentNode.removeChild(progressImg);
    	msgForm.style.display = "block";
    	document.getElementById("msgRecipient").value = "";
    	document.getElementById("msgSubject").value = "";
    	document.getElementById("msgContent").value = "";
    	} else {
    		alert(ajaxResponse)
    	}
    At least 98% of internet users' DNA is identical to that of chimpanzees

  3. #3
    Join Date
    Jan 2009
    Posts
    53
    Thanks; I can't believe I missed that.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles