Solved

programmatically submitting a form with validation

Posted on 2008-10-16
2
260 Views
Last Modified: 2013-11-05
Hi,

I have a form, which is sometimes submitted by clicking a submit button, sometimes by enter being pressed in a field, and sometimes programmatically (By the clicking of a "Master Save" elsewhere on the page).

So I created an onsubmit event to do field validation. This works for the first two methods, but breaks for the third. (Ridiculously, the submit() function doesn't trigger onsubmit!)

To hack my way around that, I call the onsubmit event programatically too, but as the form is in an IFrame and the "Master Save" is in the parent page, I can't call the javascript function by name, and have to do this:

if (document.getElementById('IFrame1').contentDocumen t.forms[0].onsubmit())
document.getElementById('IFrame1').contentDocument .forms[0].submit();

This works fine in FF, but IE6 is giving me issues. I know, IE6 is ancient, I have no choice, that's the browser the company mandates.

Can anyone suggest why this is breaking, or how else I can call the function in the IFrame?

Thanks,
Rich
0
Comment
Question by:Phyrefly
2 Comments
 
LVL 7

Accepted Solution

by:
bluV11t earned 350 total points
ID: 22729635
Got the master submit to submit the form but it does not validate
//master save button
<input type=button value="master_submit" onclick="JavaScript=submit_iframe();" />
 
//Javascript function in parent page to call submit of form in iframe
 function submit_iframe(){
     var x = document.getElementById('IFrame1');
 
    if (x.contentWindow) {
    x = x.contentWindow.document.forms[0];
    }
    else {
    x = x.contentDocument.forms[0];
    }
    return(x.submit());
 }

Open in new window

0
 
LVL 1

Author Comment

by:Phyrefly
ID: 22729695
Thank you, that iis what I was missing, it works now.

To make it validate as well, I also had to do this in the IFrame itself:

      var f = document.getElementById('DetailsForm');
      f._submit = f.submit;
      f.submit = function() { if (SanityCheck()) { this._submit() } };

Rich
0

Featured Post

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Add Clickable Links to Google Map Markers 3 29
how can i count words? 2 44
Browser Chrome downloads colored link 5 41
Multiflying 2 Input Text On a Table 7 19
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
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…

777 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