0

Issue on IE, If I run this script in all browsers except IE, It alert form submitted once, but if I try on IE, it alert twice,

what could be the reason ?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php
if(isset($_POST['btn_submit']) && $_POST['btn_submit'] == 'Submit')
{
    ?>
        <script language="javascript">  
        alert('form submitted');
        </script>    
    <?php   
}
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form id="name" method="post">
    <input type="file"/>
    <input type="submit" name="btn_submit" value="Submit" />
</form> 
</body>
</html>

Edit : I tried this code on IE7 and IE8

1
  • Did you leave out any part? Is that part of an (i)frame? Is Ajax involved ?
    – nl-x
    Commented Nov 25, 2013 at 8:06

2 Answers 2

2

Try your js at the end of the script:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form id="name" method="post">
    <input type="file"/>
    <input type="submit" name="btn_submit" value="Submit" />
</form> 
</body>
</html>
<?php
if(isset($_POST['btn_submit']) && $_POST['btn_submit'] == 'Submit')
{
    ?>
        <script language="javascript">  
        alert('form submitted');
        </script>    
    <?php   
}
?>
1
  • How is this an answer to the question 'Why is it alerting twice?'
    – nl-x
    Commented Nov 25, 2013 at 8:10
0

Try in this way, its a bit clean way of doing it.

  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  <html xmlns="http://www.w3.org/1999/xhtml">
  <head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>Untitled Document</title>
  <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
  <script type="text/javascript"> 
  $(document).ready(function() {
    $('#name').submit(function(event){
         event.preventDefault();
         // Do other stuff   
         alert('form submitted');
    });
   });
  </script>
  </head>
  <body>
     <form id="name" method="post">
        <input type="file"/>
        <input type="submit" name="btn_submit" value="Submit" />
     </form> 
  </body>
  </html>
2
  • How is this an answer to the question 'Why is it alerting twice?'
    – nl-x
    Commented Nov 25, 2013 at 8:09
  • event.preventDefault(); to prevent form getting it invoked by itself, but the code shared is an idea of how to use it in other way, he may find him benfitial to him or not. Hope I made my point :) Commented Nov 25, 2013 at 8:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.