Networking | Hardware | Software | Multimedia | System | Unix&Linux | MBA

Home>>Hardware>>validate using ONSUBMIT vs ONUNLOAD

validate using ONSUBMIT vs ONUNLOAD

Tony Davis
10-12-2005, 09:18 PM
Instead of using a submit button on my form I am using an image with an onclick function. My field validation function will therefore not execute when that image/button is clicked. The form was created with GoLive, and the functions associated with the image/button are necessary, so I don’t know that I can change that. So, I tried using onunload, which execute the validation function OK, but of course, if there are any errors, the next page is displayed regardless.

Does anyone have any suggestions how to get around this?
Maybe it is just a syntax issue that someone else might notice?

Here is some of the code in question:

<script type="text/javascript">
function validate_fields() {
for (x=0; x<document.pagethree.elements.length; x++) {
if (document.pagethree.elements[x].value == "") {
alert("Required fields are blank!.")
break; }
}
return false;
}
</SCRIPT>

<form onsubmit="validate_fields()">

<a title="Click to advance to next page" onclick="CSAction(new Array(/*CMP*/'62802300'));return CSClickReturn();" href=http://www.codingforums.com/archive/index.php/http://www.codingforums.com/archive/index.php/http://www.codingforums.com/archive/index.php/"#" csclick="62802300"><img src=http://www.codingforums.com/archive/index.php/http://www.codingforums.com/archive/index.php/"images/button_right_arrow.gif" alt="Click to advance to next page" name="mySubmit" height="50" width="50" border="0"></a>

When I do it like this, I get an error when I change the above to <input type="image"> that says mySubmit is null or not an object?

<input type="image" src=http://www.codingforums.com/archive/index.php/http://www.codingforums.com/archive/index.php/"images/button_right_arrow.gif" title="Click to advance to next page" onclick="CSAction(new Array(/*CMP*/'62802300'));return CSClickReturn();" href=http://www.codingforums.com/archive/index.php/http://www.codingforums.com/archive/index.php/http://www.codingforums.com/archive/index.php/"#" csclick="62802300" alt="Click to advance to next page" name="mySubmit" height="50" width="50" border="0"></div>

You can see the two examples at:

http://www.tdavisconsulting.com/kenerly/page03c.html
http://www.tdavisconsulting.com/kenerly/page03d.html

Thanks,
-tdavis

AlexVN
10-12-2005, 11:46 PM
Your validate_fields probably requires some correction:

<script type="text/javascript">
function validate_fields() {
var elements = document.pagethree.elements;
for (var x=0; x < elements.length; x++) {
if (elements[x].value == "") {
alert("Required fields are blank!.")
return false;
}
}
return true;
}
</script>


Then try the following (not sure that will work, but IMHO should):
<a title="Click to advance to next page" onclick="CSAction(new Array(/*CMP*/'62802300'));return (validate_fields() && CSClickReturn());" href=http://www.codingforums.com/archive/index.php/http://www.codingforums.com/archive/index.php/http://www.codingforums.com/archive/index.php/"#" csclick="62802300">

felgall
10-12-2005, 11:46 PM
get rid of the name="mysubmit" out of the <input type="image" version as it is not needed.

Tony Davis
10-13-2005, 03:37 PM
I added the (validate_fields() && CSClickReturn()); to the image/button, and sure enough, the validation routine is executed. But, just like with the onunload, even if there are errors the action= program is executed and on it goes.

How do I stop it from proceeding when there are errors?
I would have thought that the return false; would do it.

Thanks,
-tdavis


 

TOP

For more info

setting a minimum size
Auto Preview of Image 
Refresh with a query s
JS Validation obsolete
Javascript Pop up func
Slide show transitions
I'm a newbie...please!
how to write coding in
Advanced Debug Info 
.js file doesn't work 

News Archive

Adding Graphic To Text
re-direct form after s
pop up window controls
Clock on homepage - He
passing a param from a
Password Procection wi
document.title in same
focus onload 
Counting Wrong from Ri
Help needed on how to 

Related stories:

data from forms
Cross-Browser Menu Now Working, BUT Now Have FireFox Refresh Loop
How do you write maintainable code?
How to excecute 2 different form validation Java scrpt with 1 submit button ?
I want to Resize frames on a button click
Need Cross-Browser Capable Menu / Script - event.srcElement to getElementById
Simply splitting a date up?
Link Extractor Mod to Get Page Domains

Copyright@2004-2005 www.zzcoke.com All Right Reserved

advanced web statistics