Announcement Announcement Module
Collapse
No announcement yet.
Why refresh parent page before submit child form. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Why refresh parent page before submit child form.

    Hi,

    I use javascript to submit a child form and then refresh parent page.
    But every first time when I use javascript to submit the child page and then refresh parent page, the parent page get refresh first before submitting the child form.

    If I reopen the child page and resumit the child form again, it is in the right order: submit the child form then refresh its parent page.

    Here is the child page jsp file:

    Code:
      <%@page contentType="text/html;charset=UTF-8"%>
    <%@page pageEncoding="UTF-8"%>
    <%@ page session="false"%>
    <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
    <!-- http://www.roseindia.net/tutorial/spring/spring3/web/spring-3-mvc-fileupload-example.html -->
    <html>
    <head>
    <META http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <title>Upload Category Image File</title>
    
    <script language="JavaScript">
            function Validate()
              {
                     var image =document.getElementById("image").value;
                     if(image!=''){
                              var checkimg = image.toLowerCase();
                              if (!checkimg.match(/(\.jpg|\.png|\.JPG|\.PNG|\.jpeg|\.JPEG)$/)){
                                      alert("Please enter  Image  File Extensions .jpg,.png,.jpeg");
                                      document.getElementById("image").focus();
                                      return false;
                                }
                             }
                     return true;
             }			
             
             
             function refreshParent() {
                 var URL = unescape(window.opener.location.pathname);  
                 var PARMS = unescape(window.opener.location.search);
    
    //            window.opener.location.href=window.opener.location.href;
    
                var ms = new Date().getTime();
                window.opener.location.href="/HousewareAdmin-web/categories/create"+ms+PARMS;
                window.close();
             }
             
             function submitUploadForm(){   
                 this.document.forms['uploadImagePopupForm'].submit();
                 refreshParent(); 
             }
              
    </script>
    </head>
    <body>
    <form:form modelAttribute="categoryPageBean" name="uploadImagePopupForm" method="post"
    	enctype="multipart/form-data" onSubmit="return Validate();">
    	<fieldset><legend>Upload Category Image</legend>
    	<table>
                            
    		<tr>  
    			<td><form:label for="fileData" path="fileData">Image File</form:label><br />
    			</td>
    			<td><form:input path="fileData" id="image" type="file" /></td>
                    </tr>
                    <tr>
     
                            <td>
                            <a onClick="submitUploadForm();" data-type="submit" class="button-1" >Upload File</a>
                            </td>
    		</tr>
    	</table>
    	</fieldset>
    </form:form>
    </body>
    </html>
    Any suggestion is very appreciated.
    Thanks
    Sam
Working...
X