function not called from onsubmit code

S

Steve Brecher

I have some code comprising the onsubmit attrribute of a form. The code is
executing, but apparently a function called as the last statement is not
executed. The form content is submitted to the server. The behavior is the
same in Firefox and IE (current Windows versions). The following is
excerpted from the browser's "View source":

<script type="text/javascript">
function verify(f)
{
var msg;
var empty_fields = "";
var unselected = "";
var selected = 0;
alert('In verify()'); // not executed
// ...
}
</script>

<form name="ccform" id="ccform" method="post" action="/admin/index.php"
onsubmit="
alert('In onsubmit 1'); // executed
this.type.oneRequired = true;
this.donationtype.oneRequired = true;
this.fname.required = true;
this.lname.required = true;
this.email.required = true;
alert('In onsubmit 2'); // executed
return verify(this);
">
 
E

Evertjan.

Steve Brecher wrote on 08 jul 2006 in comp.lang.javascript:
I have some code comprising the onsubmit attrribute of a form. The
code is executing, but apparently a function called as the last
statement is not executed. The form content is submitted to the
server. The behavior is the same in Firefox and IE (current Windows
versions). The following is excerpted from the browser's "View
source":

<script type="text/javascript">
function verify(f)
{
var msg;
var empty_fields = "";
var unselected = "";
var selected = 0;
alert('In verify()'); // not executed
// ...
}
</script>

<form name="ccform" id="ccform" method="post"
action="/admin/index.php"
onsubmit="
alert('In onsubmit 1'); // executed

It fails in these 5 lines below
this.type.oneRequired = true;
this.donationtype.oneRequired = true;
this.fname.required = true;
this.lname.required = true;
this.email.required = true;

or, deleting them the 3rd alert is shown.
alert('In onsubmit 2'); // executed
return verify(this);
">
<input type=submit>
</form>
 
L

Lasse Reichstein Nielsen

Steve Brecher said:
<script type="text/javascript">
function verify(f)
{
var msg;
var empty_fields = "";
var unselected = "";
var selected = 0;
alert('In verify()'); // not executed

None of these lines can fail.

You have omitted lines here. If one of these lines has a syntax
error, then the entire function declaration fails, and no function
named "verify" is available to be called later.

What errors does the javascript console show?

/L
 
S

Steve Brecher

Lasse Reichstein Nielsen said:
You have omitted lines here. If one of these lines has a syntax
error, then the entire function declaration fails, and no function
named "verify" is available to be called later.

What errors does the javascript console show?

It shows a syntax error. Thanks! (Obviously I'm inexperienced with js.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top