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
LVL 1
garyennisAsked:
Who is Participating?
 
ZvonkoConnect With a Mentor Systems architectCommented:
No problem at all.
But I do not think you can give less then offered points.
What you can do is to ask Community Support for assistance: http:/Community_Support/askQuestion.jsp
0
 
ZvonkoSystems architectCommented:
If the submit() is on parent page, then it has to be:

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


0
 
ZvonkoSystems architectCommented:
And that statement is best called from a function called from the iFrame onLoad event handler.

0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
garyennisAuthor Commented:
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.  

0
 
ZvonkoSystems architectCommented:
Can you show the complte html source of that iframe page?
Does the word "submit" occures anywere else on that page?
0
 
garyennisAuthor Commented:
<!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>
0
 
garyennisAuthor Commented:
so to confirm- this page gets loaded into an iframe in the following format:

login.php?autologin&user&pass

Gary
0
 
ZvonkoSystems architectCommented:
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
0
 
ZvonkoSystems architectCommented:
Sorry, forget it. That problem occur only with split(RegExp)

0
 
garyennisAuthor Commented:
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
0
 
ZvonkoSystems architectCommented:
But can you please alert the query string?
Like :
function submitform(){
alert(location.search+"<<");

0
 
ZvonkoSystems architectCommented:
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?
0
 
garyennisAuthor Commented:
yes - the alert all works and displays fine.

0
 
garyennisAuthor Commented:
Changes the submit botton - no difference
0
 
garyennisAuthor Commented:
any progress?
0
 
ZvonkoSystems architectCommented:
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?

0
 
garyennisAuthor Commented:
<iframe title="jobs frame" id="myframe" src="/jobs/thefile.php" scrolling="no" marginwidth="0" marginheight="0" frameborder="0" style="overflow:visible; width:100%; "></iframe>
0
 
garyennisAuthor Commented:
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
0
 
ZvonkoSystems architectCommented:
Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.