473,382 Members | 1,400 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Hooking into page's onsubmit event from code within page?

Hi All,

Where I work we're using a reasonably basic tool to build web pages
and forms, that doesn't allow us to edit any source HTML and doesn't
allow us to access header content or the <BODYtags at all.

We've discovered that one of the 'field types' we can add to a form
will allow us to include javascript functions and also HTML elements
that appear to be accurately interpreted when the page is rendered,
but our most pressing need at the moment is to be able to figure out a
way to perform form field validation of the form controls when the
page is submitted.

As above, I can't edit any of the properties of the submit button
itself, and can't edit properties of the BODY tag or anything that
appears within the HEAD tags. I can only insert Javascript as a text
element into the page itself.

Does anyone know if I can implement some javascript that gets run when
the page is loaded that enforces running of another javascript
function when the page is submitted?

Any help much appreciated!!

pt
Oct 3 '08 #1
5 3166
On Oct 3, 6:57*am, planetthoughtful <planetthought...@gmail.com>
wrote:
but our most pressing need at the moment is to be able to figure out a
way to perform form field validation of the form controls when the
page is submitted.
Try this:
-------------
function addEvtLis(o, type, handler) {
if(o.attachEvent) {
o.attachEvent("on" + type, handler);
}
else if(o.addEventListener) {
o.addEventListener(type, handler, false);
}
}

function formOnSubmitHandler(evt){
var validationPassed = true;

//your code

//prevent form submission
if( !validationPassed ){
if(evt.preventDefault) evt.preventDefault();
evt.returnValue = false;
}
}

//set handler for form submit
addEvtLis(document.myFormName, "submit", formOnSubmitHandler);
--------------

>I can only insert Javascript as a text element into the page itself
Hope script tags are intact, otherwise no javascript will work.

Does anyone know if I can implement some javascript that gets run when
the page is loaded that enforces running of another javascript
function when the page is submitted?
--------
function pageOnLoadHandler(evt){
//your code
}

//set handler for window on load
addEvtLis(window, "load", pageOnLoadHandler);
-------

- Kiran Makam
Oct 3 '08 #2

On Oct 3, 3:40*pm, Kiran Makam <kiranm...@gmail.comwrote:
On Oct 3, 6:57*am, planetthoughtful <planetthought...@gmail.com>
wrote:
but our most pressing need at the moment is to be able to figure out a
way to perform form field validation of the form controls when the
page is submitted.

Try this:
-------------
function addEvtLis(o, type, handler) {
* * if(o.attachEvent) {
* * * * o.attachEvent("on" + type, handler);
* * }
* * else if(o.addEventListener) {
* * * * o.addEventListener(type, handler, false);
* * }

}

function formOnSubmitHandler(evt){
* * var validationPassed = true;

* * //your code

* * //prevent form submission
* * if( !validationPassed ){
* * * * if(evt.preventDefault) evt.preventDefault();
* * * * evt.returnValue = false;
* * }

}

//set handler for form submit
addEvtLis(document.myFormName, "submit", formOnSubmitHandler);
--------------
I can only insert Javascript as a text element into the page itself

Hope script tags are intact, otherwise no javascript will work.
Does anyone know if I can implement some javascript that gets run when
the page is loaded that enforces running of another javascript
function when the page is submitted?

--------
function pageOnLoadHandler(evt){
* * //your code

}

//set handler for window on load
addEvtLis(window, "load", pageOnLoadHandler);
-------

- Kiran Makam
Hi Kiran,

I should have mentioned that your solution hit the spot exactly!

Thank you very much!

pt
Oct 13 '08 #3
On Oct 3, 1:40*am, Kiran Makam <kiranm...@gmail.comwrote:
On Oct 3, 6:57*am, planetthoughtful <planetthought...@gmail.com>
wrote:
but our most pressing need at the moment is to be able to figure out a
way to perform form field validation of the form controls when the
page is submitted.

Try this:
-------------
function addEvtLis(o, type, handler) {
* * if(o.attachEvent) {
* * * * o.attachEvent("on" + type, handler);
* * }
* * else if(o.addEventListener) {
* * * * o.addEventListener(type, handler, false);
* * }

}
Always use typeof to test host object methods.
>
function formOnSubmitHandler(evt){
* * var validationPassed = true;

* * //your code

* * //prevent form submission
* * if( !validationPassed ){
* * * * if(evt.preventDefault) evt.preventDefault();
* * * * evt.returnValue = false;
Don't augment host objects.

Oct 13 '08 #4
On Oct 13, 10:29*am, David Mark <dmark.cins...@gmail.comwrote:
On Oct 3, 1:40*am, Kiran Makam <kiranm...@gmail.comwrote:
On Oct 3, 6:57*am, planetthoughtful <planetthought...@gmail.com>
wrote:
but our most pressing need at the moment is to be able to figure out a
way to perform form field validation of the form controls when the
page is submitted.
Try this:
-------------
function addEvtLis(o, type, handler) {
* * if(o.attachEvent) {
* * * * o.attachEvent("on" + type, handler);
* * }
* * else if(o.addEventListener) {
* * * * o.addEventListener(type, handler, false);
* * }
}

Always use typeof to test host object methods.
Is there any case where a typeof would have distinct benefit over the
way Kiran has done?
function formOnSubmitHandler(evt){
* * var validationPassed = true;
* * //your code
* * //prevent form submission
* * if( !validationPassed ){
* * * * if(evt.preventDefault) evt.preventDefault();
* * * * evt.returnValue = false;

Don't augment host objects.
Don't `supplement/overuse' host objects? [Sorry, but English isn't my
first language]

/sasuke
Oct 13 '08 #5
On Oct 13, 12:13*pm, sasuke <database...@gmail.comwrote:
On Oct 13, 10:29*am, David Mark <dmark.cins...@gmail.comwrote:
On Oct 3, 1:40*am, Kiran Makam <kiranm...@gmail.comwrote:
On Oct 3, 6:57*am, planetthoughtful <planetthought...@gmail.com>
wrote:
but our most pressing need at the moment is to be able to figure out a
way to perform form field validation of the form controls when the
page is submitted.
Try this:
-------------
function addEvtLis(o, type, handler) {
* * if(o.attachEvent) {
* * * * o.attachEvent("on" + type, handler);
* * }
* * else if(o.addEventListener) {
* * * * o.addEventListener(type, handler, false);
* * }
}
Always use typeof to test host object methods.

Is there any case where a typeof would have distinct benefit over the
way Kiran has done?
function formOnSubmitHandler(evt){
* * var validationPassed = true;
* * //your code
* * //prevent form submission
* * if( !validationPassed ){
* * * * if(evt.preventDefault) evt.preventDefault();
* * * * evt.returnValue = false;
Don't augment host objects.

Don't `supplement/overuse' host objects? [Sorry, but English isn't my
first language]

/sasuke
Don't add arbitrary properties to host objects. Treat them like they
are from another planet (and very sensitive.)

At the very least, an else should be added to the nested if.
Oct 13 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Varun | last post by:
Hi There, I have a form("myRequest.asp") and the values from it are retrieved into the page ("output_Print.asp") on which I have two buttons('Save As Complete' and 'Save As Incomplete'). When the...
4
by: Stuart Wexler | last post by:
Hi, I have a form with onSubmit embedded in the <form> tag. The form is submitted programatically through javascript . While the form submits fine, nothing I'm doing seems to get it to...
3
by: Bill | last post by:
Hi. I have a multi-page form where the user enters datails to be submitted to a database on the final page. To move through the pages I have Next and Previous buttons using the following...
3
by: Itai | last post by:
I have an aspx file named index.aspx which contains two ‘form' sections, one that has the runat=server attribute (e.g From1) and one which is a regular HTML form (e.g SignInForm). I am trying...
3
by: Rick Strahl [MVP] | last post by:
I'm working on an app that's using the WebBrowser control. I got the control working fine, hooking to the document object. But I've run into a major issue with hooking the Document events....
2
by: Dave A | last post by:
I am stuggling with databinding a drop down list, hooking into the SelectedIndexChanged and attempting to avoid using the viewstate. The drop down list is quite large so I would prefer to avoid...
6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
8
by: pigeonrandle | last post by:
Hi, Has anyone had any experience with hooking messages in other application windows (like SPY++). I want to listen for WM_MOVE messages, but can only seem to find examples of Keyboard and Mouse...
3
by: Aaron | last post by:
I'm trying to parse a table on a webpage to pull down some data I need. The page is based off of information entered into a form. when you submit the data from the form it displays a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.