jat
jat

Reputation: 7422

Issue using jquery on Internet Explorer

Jquery does not work on the Internet explorer . However it runs on other webbrowsers . The code which I wrote is

<html>
<head>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
    <script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery.validate/1.7/jquery.validate.min.js"></script>
    <script type="text/javascript">
    $(document).ready(function(){
        $("#myform").validate({
            debug: false,
            rules: {
                name: "required",
                email: {
                    required: true,
                    email: true
                }
            },
            messages: {
                name: "Please let us know who you are.",
                email: "A valid email will help us get in touch with you.",
            },
            submitHandler: function(form)
            {
                $.post('process.php', $("#myform").serialize(), function(data)
                {
                    $('#results').html(data);
                });
            }
        });
    });
    </script>

</head>
<body>
<form name="myform" id="myform" action="" method="POST">
    <label for="name" id="name_label">Name</label>
    <input type="text" name="name" id="name" size="30" value=""/>
    <br>
    <label for="email" id="email_label">Email</label>
    <input type="text" name="email" id="email" size="30" value=""/>
    <br>
    <input type="submit" name="submit" value="Submit">
</form>
<div id="results"><div>
</body>
</html>

process.php

<?php
    print "Form submitted successfully: <br>Your name is <b>".$_POST['name']."</b> and your email is <b>".$_POST['email']."</b><br>";
?>

How do I run this code on INTERNET EXPLORER .Any help is very much appreciated on this

Upvotes: 2

Views: 131

Answers (4)

Suave Nti
Suave Nti

Reputation: 3757

Remove ',' after this line

email: "A valid email will help us get in touch with you.",

should be

 email: "A valid email will help us get in touch with you."

In your messages block it is like this

 messages: {
            name: "Please let us know who you are.",
            email: "A valid email will help us get in touch with you.",   // <<<< HERE REMOVE IT                
        },

you need to remove ',' (comma) in the last line no need for it.

Upvotes: 2

Florent
Florent

Reputation: 12420

You should add return false to submitHandler.

Or you can convert your submit input to a button that doesn't submit the form using <button>Submit</button>.

Upvotes: 0

karate panda
karate panda

Reputation: 43

I tried to execute your code at my end. Please add doctype at the top. I used the same and it worked while it was not working earlier.

<!DOCTYPE html>

thanks

Upvotes: 0

Subhajit
Subhajit

Reputation: 1987

Try the below code:-

<script type="text/javascript">
  $(document).ready(function(){
    $("#myform").validate({
        debug: false,
        rules: {
            name: "required",
            email: {
                required: true,
                email: true
            }
        },
        messages: {
            name: "Please let us know who you are.",
            email: "A valid email will help us get in touch with you.",
        },
        submitHandler: function(form)
        {
            $.post('process.php', $("#myform").serialize(), function(data)
            {
                $('#results').html(data);
            });
            return false;
        }
    });
});
</script>

Upvotes: 0

Related Questions