Klapsius
Klapsius

Reputation: 3359

Submit not working with IE

Simple jquery script:

$( "#action" ).submit(function( event )
 {
     if ($("#field_name").val() == 1 ){
         alert('1');
         return true;}
         else {
             alert('no');
         return false;}
  });

This script work with FF but nothing happens on IE. How to validate/check form on IE?

Upvotes: 0

Views: 68

Answers (2)

iCollect.it Ltd
iCollect.it Ltd

Reputation: 93551

Your code works fine: http://jsfiddle.net/TrueBlueAussie/y4y83/1/

DOM Ready?

The most likely cause is not wrapping your jQuery in a DOM ready event.

$(function () {
    $("#action").submit(function (event) {
        if ($("#field_name").val() == 1) {
            alert('1');
            return true;
        } else {
            alert('no');
            return false;
        }
    });
});

$(function () { is just a shortcut for $(document).ready(function(){

Without that, the browser load time will have an impact, depending on the jQuery code placement (not at end of body etc)

Include JQuery?

The sample JSFiddles provided in comments had broken HTML. not also none of them included jQuery. please ensure you are including jQuery correctly.

Upvotes: 2

Pete_Gore
Pete_Gore

Reputation: 634

You can also use the onSubmit event in the HTML form code ; which is working better on IE.

<form ... onSubmit="return checkForm();">
   // form
</form>    

<script>
    function checkForm(){
        // your function that should return true or false
    }
</script>

Upvotes: -1

Related Questions