?
Solved

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

Posted on 2006-07-11
19
Medium Priority
?
687 Views
Last Modified: 2007-12-19
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
0
Comment
Question by:garyennis
  • 10
  • 9
19 Comments
 
LVL 63

Expert Comment

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

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


0
 
LVL 63

Expert Comment

by:Zvonko
ID: 17079773
And that statement is best called from a function called from the iFrame onLoad event handler.

0
 
LVL 1

Author Comment

by:garyennis
ID: 17079802
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 63

Expert Comment

by:Zvonko
ID: 17079845
Can you show the complte html source of that iframe page?
Does the word "submit" occures anywere else on that page?
0
 
LVL 1

Author Comment

by:garyennis
ID: 17079865
<!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
 
LVL 1

Author Comment

by:garyennis
ID: 17079878
so to confirm- this page gets loaded into an iframe in the following format:

login.php?autologin&user&pass

Gary
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 17079890
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
 
LVL 63

Expert Comment

by:Zvonko
ID: 17079906
Sorry, forget it. That problem occur only with split(RegExp)

0
 
LVL 1

Author Comment

by:garyennis
ID: 17079920
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
 
LVL 63

Expert Comment

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

0
 
LVL 63

Expert Comment

by:Zvonko
ID: 17079951
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
 
LVL 1

Author Comment

by:garyennis
ID: 17079967
yes - the alert all works and displays fine.

0
 
LVL 1

Author Comment

by:garyennis
ID: 17079979
Changes the submit botton - no difference
0
 
LVL 1

Author Comment

by:garyennis
ID: 17080388
any progress?
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 17080504
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
 
LVL 1

Author Comment

by:garyennis
ID: 17080885
<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
 
LVL 1

Author Comment

by:garyennis
ID: 17081000
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
 
LVL 63

Accepted Solution

by:
Zvonko earned 2000 total points
ID: 17083661
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
 
LVL 63

Expert Comment

by:Zvonko
ID: 17084263
Thanks.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question