...

View Full Version : Hey javascript gods - iframe and onsubmit issue



RobRichard
06-20-2002, 05:49 PM
I have a strange issue that someone may be able to help with...

I have an iframe on a page, and inside the iframe is another page with a form and some text fields and the like. I have a toolbar on the main page with a "SAVE" button on it, and the onclick of the button calls the iframe's form's submit method. I want to place some javascript in the onsubmit of the page with the form, but it ignores the onsubmit event. Everything is setup as you would do it if the page were by itself (ie, in the form tag I have onsubmit="javascript:doVerify();") but "doVerify" never executes. Any ideas Javascript gods?

JohnKrutsch
06-20-2002, 06:23 PM
Post the code for you form and the doVerify function. Typically the onsubmit call would look like this:

onsubmit="return doVerify()"


I can't think of a time when you wouldever have to put:

javascript:

into a javascript event handler.

RobRichard
06-21-2002, 04:11 AM
hmmmm, perhaps I didn't layout the scenario well enough. Let's try this sample...

Create two HTML pages, call one page1.htm, the other call page2.htm. Put the code for each page accordingly...

page1.htm:

<html>
<head>
<script>
function doSaveClick() {
window.maintframe.document.forms(0).submit();
}
</script>
</head>
<body>
<center>
<input type=button id="save" name="save" value="save" onclick="javascript:doSaveClick();">
<p>
<iframe height="300" width="300" id="maintframe" name="maintframe" border="1" frameborder=1 scrolling="auto" src="page2.htm"></iframe>
</center>
</body>
</html>



page2.htm:

<html>
<head>
<script>
function doVerify() {
alert('Doing the verify function!');
}
</script>
</head>
<body>
<form id=maint name=maint onsubmit="return doVerify()">
Enter something: <input type=text id=txtText name=txtText>
<p>
Enter something else: <input type=text id=Text2 name=txtText2>
</form>
</body>
</html>


Then pull up page1.htm, and click the "Save" button. The form in the iframe submits, but the function doVerify is never executed. Is there a way to make that function fire? Or, is there a way to call doVerify from the button click?

Thanks for your help...

RobRichard
06-21-2002, 04:54 AM
OH OH OH OH OH! Great idea... I tried a couple of variations and here is what works:

In the doSaveClick function:

function doSaveClick() {
window.maintframe.document.forms(0).submit();
window.maintframe.doVerify();
}

Works like a champ!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum