Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Submit form in IFRAME

Status
Not open for further replies.

TheObserver

Programmer
Mar 26, 2002
91
US
I need to submit a form in an IFRAME to itself from the parent document/page. I believe I've gotten the JS written correctly to do this. It works just fine in IE (I know that IE is pretty error tolerant) - the IFRAME submits to itself. However, in NS, the IFRAME submits and the entire parent window gets submitted. I need for this to not occur.

Here is the JS I'm using:
onClick="parent.hiddeniframe.hiddensub.MYVAL.value='SELECTED_VAL'; parent.hiddenframe.hiddensub.submit();"

Here is how my IFRAME is defined:
<IFRAME SRC="hiddeniframe.jsp" NAME="HIDDEN" ID="HIDDEN" style="width:100px; height:100px; border: 0px"></IFRAME>

And here is the actual form in the hiddeniframe.jsp file:
<FORM NAME="hiddensub" ACTION="hiddeniframe.jsp">
<INPUT TYPE="HIDDEN" NAME="MYVAL" VALUE="">
</FORM>

Thanks for your time.
 
Thanks for your response. I tried that but the same things are happening - submits fine with IE, submits the whole page with NS.

 
Okay, I've been testing some things and hopefully I can get some help to get around this...I'll post in a new thread if need be...

I am trying to do the form submit trigger from a button. I've noticed with some testing that IE will allow you to use buttons to trigger actions, but NS will trigger the action and then submit the page that the form is in. Is there some way to keep NS from submitting the page and just use the buttons as event triggers?

Also, I am using <BUTTON></BUTTON> for the inputs here, rather than <INPUT TYPE="BUTTON"...>. I did this because I need to set the size of the buttons to a certain width and I was unable to do so with the <INPUT...> way of creating the buttons.
 
first of all, you can set the width of any element, even elements intended to have no width, with the proper CSS.

second of all, if you are trying to prevent the submission of a form based on certain criteria, you should call a function from the form's onsubmit event, rather than from a button's onclick event, and have the call return the returned value. yes, this sounds confusing, but it's not.

for example, the following form will never submit.

Code:
<script language="javascript"><!--
function doCheck() {
    return false;
}
--></script>

<form onsubmit="return doCheck();">
  <input type="submit" />
</form>

*cLFlaVA
----------------------------
[tt]0101 is binary code for "supreme programmer of omnipotent power"[/tt] - adam0101
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Okay, I've been testing some things and hopefully I can get some help to get around this...I'll post in a new thread if need be...

I am trying to do the form submit trigger from a button. I've noticed with some testing that IE will allow you to use buttons to trigger actions, but NS will trigger the action and then submit the page that the form is in. Is there some way to keep NS from submitting the page and just use the buttons as event triggers?

Also, I am using <BUTTON></BUTTON> for the inputs here, rather than <INPUT TYPE="BUTTON"...>. I did this because I need to set the size of the buttons to a certain width and I was unable to do so with the <INPUT...> way of creating the buttons.
 
Sorry about the duplicate post.

Here's what I have...I have a page with several iframes embedded within it. This page is contained in a tabset with two other pages. This page is on the third tab in the set. One of the iframes in the page is used for remote scripting so I can set variables on the server side for server side coding. I need to set values in a form in this one iframe and occasionally submit it to get the values back to the server.

This works just fine in IE - the JS tied to the button's onClick event submits the form in the iframe and nothing else occurs. However, NS submits the whole page. This can't happen - if the whole page is submitted the current tab is set back to the first tab, and the user has to click back to the third tab, which leads to a whole mess of user comprehension problems.

So, is there a way to keep NS from submitting the whole page? The reason I brought up the buttons is that I tested with an alternate approach - creating the form in a popup window - but NS still submitted the page when I tried to get the form in the popup to submit. Is there something inherent about the buttons that would make this happen? Could I get around it with links or something else?
 
I had the same problem, and if I remember correctly this is how I got around it:
Code:
// form definition:
<form name="myform" onsubmit="return false;">
// that should keep the form from getting submitted
// when you don't want it to.

// then in your button click code
document.myform.submit();
// that will submit the form (no matter what onsubmit says)

Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top