Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

.submit()

Posted on 2002-07-09
9
Medium Priority
?
954 Views
Last Modified: 2009-12-16
I have a form with validation code and want to submit the form via an image as a button.

The form setup is:
<form name=myForm action=myAction.asp method=post onSubmit="return doValidate(myForm)">

The submit image is:
<a href=# onClick=submit()><image src=myImage.gif></a>

The javascript validation is:
function doValidate(formObj){
return true;
}

This code never fires doValidate.

How is the submit() method used?
0
Comment
Question by:vogtster
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 7141409
<form name=myForm action=myAction.asp method=post onSubmit="return doValidate('myForm')">

or :

<form name=myForm action=myAction.asp method=post onSubmit="return doValidate(this)">

0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 7141410
This:

<a href=# onClick=submit()><image src=myImage.gif></a>


may need to be:

<a href=# onClick="javascript:document.forms[0].submit()"><image src=myImage.gif></a>


Fritz the Blank
0
 

Author Comment

by:vogtster
ID: 7141441
That does not work. I know because I put an "alert('validate')" in the doValidation function to help me see if it is firing and I never see the alert.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 7141481
Let me know how this works for you. If you like, I can generalize it so that you don't have include the name of the form in the function:

<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
<SCRIPT LANGUAGE=javascript>
<!--
function doValidate(formObj){
alert("Hey there!");
document.myForm.submit();
return true;
}
//-->
</SCRIPT>


</HEAD>
<BODY>

<form name="myForm" action="myAction.asp" method=post onSubmit="return doValidate(this)">

The submit image is:
<a href=# onClick="javascript:doValidate()"><img src=myImage.gif></a>



</BODY>
</HTML>
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 7141511
or this:

<a href="#" onClick="if(doValidate(document.myForm))document.myForm.submit();return false;"><img src="myImage.gif"></a>
0
 

Author Comment

by:vogtster
ID: 7141536
I know I can call the doValidate function directly from the image click.

I don't want to call doValidate from the image click, but rather cause the form's onSubmit function to fire.
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 7141567
When you call the submit method of a form the onSubmit will NOT be fired. This is the design of the form! There is no way you can call the submit method and have the onSubmit event fired.

You can either use:
<input type="image" src="myImage.gif" border="0">
instead of:
<a href=# onClick=submit()><image src=myImage.gif></a>

or:

<a href=# onClick="if(doValidate(document.forms['myForm'])document.forms['myForm'].submit()"><image src="myImage.gif"></a>


CJ

0
 
LVL 22

Accepted Solution

by:
CJ_S earned 400 total points
ID: 7141572
Sorry, I repeated KeK's comment (didn't see it).

>> I don't want to call doValidate from the image click, but rather cause the form's onSubmit function to fire.

You can't with your current design, use input type=image instead (please note that this tag also needs to be INSIDE the form!)
0
 

Author Comment

by:vogtster
ID: 7141592
Oops! I've been using buttons for so many years I forgot all about the image type input button. Thanks.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
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…

719 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