Problem with Javascript submit

R

Rabel

I am a flash designer so I dont know a whole lot about the javascript
submit buttons (I may not even be describing it right sorry) but here
is the code I am using.

<IMG name="Checkout" value="Checkout" SRC="imagesButtons/
purchaseButton_r2_c2.jpg" onMouseOver="this.src = 'imagesButtons/
purchaseButton_r2_c2_f2.jpg'" onMouseOut="this.src = 'imagesButtons/
purchaseButton_r2_c2.jpg'"
onClick="JavaScript:document.forms[0].submit()">

That works but the problem is before I was using a <input
type="submit"> and this did the validation I set up like this

onSubmit="WAValidateAN(document.checkout_AN_Loc.x_first_name,document.checkout_AN_Loc.x_first_name.value,'-
Invalid character in first
name',true,true,false,true,'',document.checkout_AN_Loc.x_first_name,
0,true);">

Now there is a whole lot of text I cut out so if the code is a little
off dont worry - it works fine, but I dont know how to make it call
this. I thought since that I have told the form to submit and the form
is told that on submit do the validation - any help is apprieciated.
Also with the button there is no mouse change (to rollover mouse
state) any idea how I change that.
 
R

Rabel

Rabel scribed:




I am a flash designer so I dont know a whole lot about the javascript
submit buttons (I may not even be describing it right sorry) but here
is the code I am using.
<IMG name="Checkout" value="Checkout" SRC="imagesButtons/
purchaseButton_r2_c2.jpg" onMouseOver="this.src = 'imagesButtons/
purchaseButton_r2_c2_f2.jpg'" onMouseOut="this.src = 'imagesButtons/
purchaseButton_r2_c2.jpg'"
onClick="JavaScript:document.forms[0].submit()">
That works but the problem is before I was using a <input
type="submit"> and this did the validation I set up like this
onSubmit="WAValidateAN(document.checkout_AN_Loc.x_first_name,document.chec­kout_AN_Loc.x_first_name.value,'-
Invalid character in first
name',true,true,false,true,'',document.checkout_AN_Loc.x_first_name,
0,true);">
Now there is a whole lot of text I cut out so if the code is a little
off dont worry - it works fine, but I dont know how to make it call
this. I thought since that I have told the form to submit and the form
is told that on submit do the validation - any help is apprieciated.
Also with the button there is no mouse change (to rollover mouse
state) any idea how I change that.

I'm a js newbie as well, but my experience is that when using
"document.forms[0].submit()" in a js, it doesn't effect the onSubmit
directive. It doesn't appear to me that the js directive replaces the submit
button, but merely submits the form according to the action directive.

My workaround has been to write a small js that submits the form for
validation and if it validates, submit it.

Thanks Ed - so could I then just move the code to the "submit" button
then
 
B

brunascle

I am a flash designer so I dont know a whole lot about the javascript
submit buttons (I may not even be describing it right sorry) but here
is the code I am using.

<IMG name="Checkout" value="Checkout" SRC="imagesButtons/
purchaseButton_r2_c2.jpg" onMouseOver="this.src = 'imagesButtons/
purchaseButton_r2_c2_f2.jpg'" onMouseOut="this.src = 'imagesButtons/
purchaseButton_r2_c2.jpg'"
onClick="JavaScript:document.forms[0].submit()">

That works but the problem is before I was using a <input
type="submit"> and this did the validation I set up like this

onSubmit="WAValidateAN(document.checkout_AN_Loc.x_first_name,document.checkout_AN_Loc.x_first_name.value,'-
Invalid character in first
name',true,true,false,true,'',document.checkout_AN_Loc.x_first_name,
0,true);">

Now there is a whole lot of text I cut out so if the code is a little
off dont worry - it works fine, but I dont know how to make it call
this. I thought since that I have told the form to submit and the form
is told that on submit do the validation - any help is apprieciated.
Also with the button there is no mouse change (to rollover mouse
state) any idea how I change that.

the "proper" way to use an image as the submit button is to use a tag
like this:

<input type="image" src="imagesButtons/purchaseButton_r2_c2.jpg" />

Put that in the form and it should act the way you want it to, and
that should also make your onSubmit code run when it's supposed to.
You should also be able to put the same onMouseOver and onMouseOut
codes into that tag.

And, yes, when you call something like form.submit() in the
javascript, the onSubmit code that you put in the form tag will
(should?) not run.
 
E

Evertjan.

Rabel wrote on 05 apr 2007 in comp.lang.javascript:
I am a flash designer so I dont know a whole lot about the javascript
submit buttons (I may not even be describing it right sorry) but here
is the code I am using.

<IMG name="Checkout" value="Checkout" SRC="imagesButtons/
purchaseButton_r2_c2.jpg" onMouseOver="this.src = 'imagesButtons/
purchaseButton_r2_c2_f2.jpg'" onMouseOut="this.src = 'imagesButtons/
purchaseButton_r2_c2.jpg'"
onClick="JavaScript:document.forms[0].submit()">

with onclick do not use the JavaScript: part, [unless you also use
clientside vbscript on the same page].

If th <img> is in the form, use:

onClick='this.form.submit()'
That works but the problem is before I was using a <input
type="submit"> and this did the validation I set up like this
onSubmit="WAValidateAN(document.checkout_AN_Loc.x_first_name,document.c
heckout_AN_Loc.x_first_name.value,'- Invalid character in first
name',true,true,false,true,'',document.checkout_AN_Loc.x_first_name,
0,true);">

Oh, that is a string I cannot possibly fathom, keep your questions simple
please.

onsubmit='' belongs in the <form> element and NOT in an <input/submit
where you should use onclick=''.

If you put the onsubmit='' in the form element, it will fire BOTH with a
submit buttom AND with a javascript submit.

However you could, in stead of a <img also use a
<input type='image' for regular submission.

Now there is a whole lot of text I cut out so if the code is a little
off dont worry - it works fine, but I dont know how to make it call
this.

Either it works, or it does not, meseems?
I thought since that I have told the form to submit and the form
is told that on submit do the validation - any help is apprieciated.

See above.
Also with the button there is no mouse change (to rollover mouse
state) any idea how I change that.

Learn to use CSS.

Perhaps you should first study the beginnings of html-forms, javascript
and css, examples and tutorials are all over the web. Google is your
friend.
 
R

Rabel

I am a flash designer so I dont know a whole lot about the javascript
submit buttons (I may not even be describing it right sorry) but here
is the code I am using.
<IMG name="Checkout" value="Checkout" SRC="imagesButtons/
purchaseButton_r2_c2.jpg" onMouseOver="this.src = 'imagesButtons/
purchaseButton_r2_c2_f2.jpg'" onMouseOut="this.src = 'imagesButtons/
purchaseButton_r2_c2.jpg'"
onClick="JavaScript:document.forms[0].submit()">
That works but the problem is before I was using a <input
type="submit"> and this did the validation I set up like this
onSubmit="WAValidateAN(document.checkout_AN_Loc.x_first_name,document..check­out_AN_Loc.x_first_name.value,'-
Invalid character in first
name',true,true,false,true,'',document.checkout_AN_Loc.x_first_name,
0,true);">
Now there is a whole lot of text I cut out so if the code is a little
off dont worry - it works fine, but I dont know how to make it call
this. I thought since that I have told the form to submit and the form
is told that on submit do the validation - any help is apprieciated.
Also with the button there is no mouse change (to rollover mouse
state) any idea how I change that.

the "proper" way to use an image as the submit button is to use a tag
like this:

<input type="image" src="imagesButtons/purchaseButton_r2_c2.jpg" />

Put that in the form and it should act the way you want it to, and
that should also make your onSubmit code run when it's supposed to.
You should also be able to put the same onMouseOver and onMouseOut
codes into that tag.

And, yes, when you call something like form.submit() in the
javascript, the onSubmit code that you put in the form tag will
(should?) not run.- Hide quoted text -

- Show quoted text -

Thanks brunas that works - thanks for the help
 

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
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top