Submit form using javascript, work in FF but not IE

I have this code.

The code below works in Firefox, but it is not in IE

<?php // file: login_dfr.php ?>
<body>
<?php
$data = getLoginData($_SESSION['whoyouare']);
?>
<form name="frm_redirect_dfr" action="<?php echo $data['url']; ?>" method="POST"     id="frm_redirect_dfr" style="display: none;">
    <input name="DFRNet_User" value="<?php echo $data['username']; ?>" type="hidden" />
    <input name="DFRNet_Pass" value="<?php echo $data['password']; ?>" type="hidden" />
    <input name="tbllogin" value="login" type="hidden" />
    <input type="submit" value="submit" />
    </form>
    <script language="javascript" type="text/javascript">
    document.forms["frm_redirect_dfr"].submit();
    </script>
</body>

      

What I want to do is when the user accesses the page, it will first try to get the login details, repeat it in the form and submit the form automatically using javascript

Update: I forgot to mention that the above code is in a frame, the mainFrame code looks like this:

<?php session_start(); ?>
<?php // file: login_frame.php ?>
<!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>Wavinet</title>
</head>
<frameset rows="1,*" frameborder="no" border="0" framespacing="0">
<frame src="topFrame.php" name="topFrame" scrolling="No" noresize="noresize" id="topFrame" title="topFrame" />
<frame src="login_dfr.php" name="mainFrame" id="mainFrame" title="mainFrame" />
</frameset>
<noframes>
<body>This page contain frame</body>
</noframes>
</html>

      

+2


a source to share


3 answers


You probably need to give IE time to render the form before you submit it. So this is with

<script language="javascript" type="text/javascript">
setTimeout(function() {
    document.forms["frm_redirect_dfr"].submit();
    }, 0) /* You may need a higher number here. If you do, start with 100 and go up. */
</script>

      



You can also hang it with a document handler or something like that, but I don't know how to do that for it (jQuery provides such a hook).

The reason for this is that it is a type of "yield". Browsers tend to give lower priority to blurring page elements than running inline JavaScript. This poses a problem with inline JavaScript that needs to interact with the DOM as there is no obvious way to wait for the browser to render it. This trick gives the browser the ability to render before JavaScript runs.

0


a source


Your code doesn't really make sense if I don't understand it. You generate the complete form with the information already available to PHP and submit it back to PHP. There is no reason, you can just include any file in your script $data['url']

and give its username and password



+1


a source


This should work fine, assuming the generated html is not mangled due to the lack of a way to escape php variable values.

Your problem might be in your script that is receiving the message. Do print_r($_POST);

to help you debug.

But as Michael Mrozek said, you probably don't need to do this at all.

0


a source







All Articles