Link to home
Start Free TrialLog in
Avatar of khan02
khan02Flag for United States of America

asked on

my onSubmit event doesn't work on IE

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

Avatar of SidFishes
SidFishes
Flag of Canada image

without looking too closely yet i'd say you've got a typo

<script> <<< remove this
<script>
Avatar of khan02

ASKER

here is the script>>>>

<script language="Javascript">
    function confirmSubmit(){
         
             var msg = "it's a test'.";
                if (confirm(msg))
                {      
                   return true;    
                }                         
                else
                {
                     return false;    
                }
                   
    }
</script>
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>
Avatar of khan02

ASKER

it was a copy paste error on this forum, but i don't have this duplicate <script> tag on my form.
Avatar of khan02

ASKER

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>
ASKER CERTIFIED SOLUTION
Avatar of khan02
khan02
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of khan02

ASKER

i giving credit to myself since i had to find an alternate way, and no one else answered anything abt this..