/    Sign up×
Community /Pin to ProfileBookmark

Submit a form in an iframe

I have two identical pages on two different servers (one is a test server, one is production).

They both use the same script to submit a form within an iframe while also closing a pseudo-modal box.

Here are the two example links:
[url]http://library.umhb.edu/website/redesign/working/borrow.html[/url] (the working page)
[url]http://umhblib.umhb.edu/screens/borrow.html[/url] (the nonworking page)

Scroll down to the bottom of either page, and click “Email Cheri Howell” (don’t worry, the actual email is not being sent at this time). A screen will pop up with a form to be filled out by our patron, as well as a submit button. The submit button is actually on the parent document, while the form above it is in an iframe. On one server, when you click it, the form submits and the box closes. On the other server – however – the form never submits, but the box still closes.

The javascript in questions:

[CODE]function subThenClose(frameType)
{
if(frameType==”email”)
{
setTimeout(‘sClose();’,2000);
window.frames[‘sFrame’].document.forms[‘mainform’].submit();
}
}[/CODE]

The accompanying HTML:

[CODE]
<div id=”screen” class=”nodisplay”>
<div id=”noshow” onclick=”sClose();”></div>
<div id=”sBody” class=”sBody”>
<p>
<a href=”javascript:sClose();” class=”sLink”>CLOSE</a>
</p>
<iframe frameborder=”0″ scrolling=”no” name=”sFrame” id=”sFrame”></iframe>
<input type=”button” onclick=”subThenClose(’email’);” name=”Submit” value=”Submit”>
</div>[/CODE]

Please help me figure out why it works on one server and not on another!

Thanks

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@Angry_Black_ManAug 22.2007 — i swear that i can never troubleshoot frame issues. i try to create a framed environment on my desktop and then access one frame from another, but i get "exception occured" and "permission denied" errors all day.
Copy linkTweet thisAlerts:
@Angry_Black_ManAug 22.2007 — in the javascript in question, do this before you submit:

alert(window.frames['sFrame'].document.forms['mainform'])

what does that alert?
Copy linkTweet thisAlerts:
@RY824RauthorAug 22.2007 — I guess I forgot to include some code, actually.

That particular line is what is supposed to submit the form ("mainform") within the the frame ("sFrame"). The sClose() call is what is responsible for closing the modal screen.

Thanks for your help and I can certainly relate with how difficult frames are to troubleshoot. I think, out of the different HTML components I have messed with, frames are by far the least accessible via javascript due to such huge differences in browser to browser coding.
Copy linkTweet thisAlerts:
@Angry_Black_ManAug 22.2007 — in your code:

function subThenClose(frameType)
{
if(frameType=="email")
{
setTimeout('sClose();',2000);
window.frames['sFrame'].document.forms['mainform'].submit();
}
}


instead of the line that submits, change that to:

alert(window.frames['sFrame'].document.forms['mainform']);

what do you get in the alert?
Copy linkTweet thisAlerts:
@RY824RauthorAug 23.2007 — When I changed that code I didn't get any alerts in either IE7 or FF2

Oddly, I also don't get any errors. It just refuses to work. Could it be something to do with the target of the iframe being on a different server from the parent page? I wouldn't expect it to, but I suppose it could be a browser safety measure.
Copy linkTweet thisAlerts:
@Angry_Black_ManAug 23.2007 — there is a distinct possibility that is the source of your problem. microsoft's MSDN notes that there are security concerns about accessing different frames from different domains, and how it blocks that.

im surprised that FF didnt show any errors there. FF usually never lets crap like that slip. im really dissapointed. but i would certainly attribute this problem to cross domain referencing within the JS.
Copy linkTweet thisAlerts:
@RY824RauthorAug 23.2007 — Well, dang. I was hoping that the whole "two servers / different iframes" thing wouldn't end up being the culprit, but it certainly seems like a possibility. I was hoping I had just overlooked something small.

What sucks is that now I am going to have to redesign this module of the site because the "live" server does not accept or support ASP, which is what this whole email form thing is built on. Woe is me, eh?

Thanks for you help!
×

Success!

Help @RY824R spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...