Solved

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

Posted on 2006-07-11
19
642 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
Comment Utility
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
Comment Utility
And that statement is best called from a function called from the iFrame onLoad event handler.

0
 
LVL 1

Author Comment

by:garyennis
Comment Utility
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
 
LVL 63

Expert Comment

by:Zvonko
Comment Utility
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
Comment Utility
<!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
Comment Utility
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
Comment Utility
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
Comment Utility
Sorry, forget it. That problem occur only with split(RegExp)

0
 
LVL 1

Author Comment

by:garyennis
Comment Utility
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 63

Expert Comment

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

0
 
LVL 63

Expert Comment

by:Zvonko
Comment Utility
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
Comment Utility
yes - the alert all works and displays fine.

0
 
LVL 1

Author Comment

by:garyennis
Comment Utility
Changes the submit botton - no difference
0
 
LVL 1

Author Comment

by:garyennis
Comment Utility
any progress?
0
 
LVL 63

Expert Comment

by:Zvonko
Comment Utility
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
Comment Utility
<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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now