Link to home
Start Free TrialLog in
Avatar of garyennis
garyennis

asked on

Auto-Submit a form - won't work when in Iframe in Firefox

I have a simple form, which uses javascript to auto-submit it (it gets passed the username/password from a string).

This all works fine, however I need to have this form within an IFRAME.

Works fine (auto-submits) when using IE, but simply appears to ignore the submit() part of the js function when viewed in Firefox.

Please help...  a working example of the above would be ideal, so i can reverse engineer my code.

Thanks
Gary
Avatar of Zvonko
Zvonko
Flag of North Macedonia image

If the submit() is on parent page, then it has to be:

window.frames.yourIframeName.document.forms[0].submit();


And that statement is best called from a function called from the iFrame onLoad event handler.

Avatar of garyennis
garyennis

ASKER

The submit function is on the "child" page (the file within the iframe).  The function all runs fine (until it gets to the document.login.submit(); command.  

Can you show the complte html source of that iframe page?
Does the word "submit" occures anywere else on that page?
<!DOCTYPE html
     PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Job Seekers</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">



<script type="text/javascript"><!--
  function validate(f){


    var regex = /^\s*$/i;
      for(var i=0; i<f.elements.length; i++){
        if(regex.test(f.elements[i].value)){
          alert("Please fill in all fields.");
          f.elements[i].focus();
          return false;
       }
    }
return true;
}


function submitform(){
var query = location.search.substring(1);  // Get query string.
var pairs = query.split("&");              // Break at &.
var passed0 = unescape(pairs[0]);
var passed1 = unescape(pairs[1]);
var passed2 = unescape(pairs[2]);
if (passed0=="autologin") {
document.login.u.value=passed1;
document.login.p.value=passed2;
document.login.submit();
}
}
//--></script>





</head>

<body onload="submitform();">



<br />


<br /><br /><br />
<h1>Login</h1>
<br />

<form action="xxxxx.php" method="post" name="login" onsubmit="return validate(this);">
    Email: <br /><input name="u" type="text" id="u">
  <br>
  Password:<br /><input name="p" type="password" id="p">
  <br>
<input type="submit" value="Submit">
</form>

</body>
</html>
so to confirm- this page gets loaded into an iframe in the following format:

login.php?autologin&user&pass

Gary
OK, I got it!
Your problem is the split()
Alert the passed0, passed1 and passed2 var values and you will see what the problem is.
Solution is to distinguish betwean browsers, for example by checking for document.all for IE
Sorry, forget it. That problem occur only with split(RegExp)

yes - as i said - the rest of the function all works fine (it - does put the correct text into the form - just doesnt auto-submitt it)

Gary
But can you please alert the query string?
Like :
function submitform(){
alert(location.search+"<<");

It should not change much, but give please the submit button a name:

<input type="submit" name="Submit" value="Submit">


How do you assign the URL for the IFRAME?
yes - the alert all works and displays fine.

Changes the submit botton - no difference
any progress?
I was on the road.
Now I will test that iframe scenario.
But it should not behavior different then that standalone page which I tested already without problems in FF.
Can you tell me how do you set the iframe URL?

<iframe title="jobs frame" id="myframe" src="/jobs/thefile.php" scrolling="no" marginwidth="0" marginheight="0" frameborder="0" style="overflow:visible; width:100%; "></iframe>
Doh!!

I worked it out...
the iframe had a display:none in the style (it also uses some js code to turn it "on"), and this all works fine in IE, but Firefox seemed to not like it.

Sorry for the hassel.

Can i give you half the points as a gesture for your help?

Gary
ASKER CERTIFIED SOLUTION
Avatar of Zvonko
Zvonko
Flag of North Macedonia 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
Thanks.