Solved

my onSubmit event doesn't work on IE

Posted on 2011-03-17
7
645 Views
Last Modified: 2012-05-11
I am using normal form on coldfusion and my javascript code is very simple to ask for confirmation before submitting a form. when i click on submit button it asks me for confirmation, but even if i press cancel, it still submits the form and it should not be. Only on IE it happen (and i m runnign IE 8). it works fine on FF and Chrome.

any help will be greatly appreciated.
here is the javaScript>>

<script>
<script>
    function confirmSubmit(){
         
             var msg = "it's a test";
                if (confirm(msg)) 
                {      
                   return true;    
                }                   	
                else
                {
        	       return false;    
                }
                   
    }
</script>

Here Is my form inside a CFM coldfusion page>>>

<form id="reqform" action="components/actions.cfc?method=insertData&num=#session.sid#" method="post" class="loginForm" onsubmit="return confirmSubmit();">         
   

	  	
		
	  
		<fieldset>  	
            <legend>Enter Dates</legend>	
                <label> Start Date <span>*</span></label> 
	  	 		<input type="text" name="start_date" id="start_date" value="" class="required">
               
                <label>End Date <span>*</span></label>
	  	 		<input type="text" name="end_date" id="end_date" value="" class="required">
               
		
	    </fieldset>
		
    			
	
    		
            <input type="submit" name="insert" value="Save" class="submit">
            <input type="submit" name="apply" value="Submit" class="submit">
        </fieldset>       					
</form>

Open in new window

here is the javaScript>>

<script>
<script>
    function confirmSubmit(){
         
             var msg = "it's a test";
                if (confirm(msg)) 
                {      
                   return true;    
                }                   	
                else
                {
        	       return false;    
                }
                   
    }
</script>

Here Is my form inside a CFM coldfusion page>>>

<form id="reqform" action="components/actions.cfc?method=insertData&num=#session.sid#" method="post" class="loginForm" onsubmit="return confirmSubmit();">         
   

	  	
		
	  
		<fieldset>  	
            <legend>Enter Dates</legend>	
                <label> Start Date <span>*</span></label> 
	  	 		<input type="text" name="start_date" id="start_date" value="" class="required">
               
                <label>End Date <span>*</span></label>
	  	 		<input type="text" name="end_date" id="end_date" value="" class="required">
               
		
	    </fieldset>
		
    			
	
    		
            <input type="submit" name="insert" value="Save" class="submit">
            <input type="submit" name="apply" value="Submit" class="submit">
        </fieldset>       					
</form>

Open in new window

0
Comment
Question by:khan02
  • 5
  • 2
7 Comments
 
LVL 36

Expert Comment

by:SidFishes
ID: 35160542
without looking too closely yet i'd say you've got a typo

<script> <<< remove this
<script>
0
 

Author Comment

by:khan02
ID: 35160567
here is the script>>>>

<script language="Javascript">
    function confirmSubmit(){
         
             var msg = "it's a test'.";
                if (confirm(msg))
                {      
                   return true;    
                }                         
                else
                {
                     return false;    
                }
                   
    }
</script>
0
 
LVL 36

Expert Comment

by:SidFishes
ID: 35160604
according to your posted example it's actually

<script> <<<< this is unclosed and will cause issues. remove it
<script>
    function confirmSubmit(){
         
             var msg = "it's a test";
                if (confirm(msg))
                {      
                   return true;    
                }                         
                else
                {
                     return false;    
                }
                   
    }
</script>
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:khan02
ID: 35160674
it was a copy paste error on this forum, but i don't have this duplicate <script> tag on my form.
0
 

Author Comment

by:khan02
ID: 35160737
seems like my script is fine, but some how it's conflicting with jquery validation. I have the following jquery validation before this script (see below). if i comment those validation script, then it works fine else it just doesn't work.


<script>
$(document).ready(function() {
      $("#start_date").datepicker(
          {
              minDate: new Date(),
              beforeShowDay: $.datepicker.noWeekends
          }
      );
      $("#end_date").datepicker(
          {
             minDate: new Date(),
             beforeShowDay: $.datepicker.noWeekends
            }
      
      );

})
</script>


 <script>
$().ready(function() {
      $("#reqform").validate({
            rules: {            
                  
                  start_date: {
                        required: true                        
                  },
                  end_date: {
                        required: true                  
                  }
            },
            messages: {                                                
                  start_date: {required: "Please enter a valid start date"},
                  end_date: {required: "Please enter a valid end date"}
                  
            }
      });
            
});
</script>
0
 

Accepted Solution

by:
khan02 earned 0 total points
ID: 35160764
Here is a Complete FORM>>>>



<link rel="stylesheet" type="text/css" href="css/form.css" media="screen" />
<link rel="stylesheet" type="text/css" href="jquery/css/ui-lightness/jquery-ui-1.8.9.custom.css" media="screen" />
<link rel="stylesheet" type="text/css" href="css/view.css" media="screen" />

<script type="text/javascript" src="jquery/js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="jquery/js/jquery-ui-1.8.9.custom.min.js"></script>
<script type="text/javascript" src="jquery/js/jquery.validate.js"></script>
<script type="text/javascript" src="jquery/js/cmxforms.js"></script>


<script>
$(document).ready(function() {
      $("#start_date").datepicker(
          {
              minDate: new Date(),
              beforeShowDay: $.datepicker.noWeekends
          }
      );
      $("#end_date").datepicker(
          {
             minDate: new Date(),
             beforeShowDay: $.datepicker.noWeekends
            }
      
      );

})
</script>


 <script>
$().ready(function() {
      $("#reqform").validate({
            rules: {            
                  start_date: {
                        required: true                        
                  },
                  end_date: {
                        required: true                  
                  }
            },
            messages: {                  
                  start_date: {required: "Please enter a valid start date"},
                  end_date: {required: "Please enter a valid end date"}
                  
            }
      });
            
});
</script>



<script language="Javascript">
    function formConfirm(){
         
             var msg = "it's a test'.";
                if (confirm(msg))
                {      
                   document.getElementById('reqform').submit();    
                }                         
                else
                {
                     return false;    
                }
                   
    }
</script>

 <cfoutput>  
<!--- components/actions.cfc?method=insertData&num=#session.sid# --->
<form id="reqform" action="components/actions.cfc?method=insertData&num=#session.sid#" method="post" class="loginForm" onSubmit="return formConfirm();">        
               
            <fieldset>        
            <legend>Enter Dates</legend>      
                <label> Start Date <span>*</span></label>
                           <input type="text" name="start_date" id="start_date" value="" class="required">
               
                <label>End Date <span>*</span></label>
                           <input type="text" name="end_date" id="end_date" value="" class="required">
               
                        <input type="hidden" name="type" value="d"><!--- Updated Oct 26, 2009 --->
          </fieldset>
            
                      
            <fieldset>
            <legend>Enter Comments</legend>
            <label>Comments
                    <textarea name="comments" id="comments"></textarea>
                            Comment will be seen by Coordinator and Administrator.
                </label>
                
            <input type="submit" name="insert" value="Save" class="submit">
            <input type="submit" name="apply" value="Submit" class="submit">
        </fieldset>                                     
</form>
</cfoutput>

0
 

Author Closing Comment

by:khan02
ID: 35957317
i giving credit to myself since i had to find an alternate way, and no one else answered anything abt this..
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
This article discusses how to create an extensible mechanism for linked drop downs.
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now