Solved

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

Posted on 2006-07-11
19
667 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

 
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 500 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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

705 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