Any way to override submit behavior for input img?

  • Thread starter christopher.secord
  • Start date
C

christopher.secord

Normally, a button like <input type="image"> is also a submit button.
Is there any way to override that so that it has an onclick event but
does not submit the form?

For what I'm trying to do, I cannot use an <img> element with onclick.
I have to use a form element (and I'd rather have an image than a
button)

Thanks in advance for any insight.
chris
 
B

bobzimuta

Normally, a button like <input type="image"> is also a submit button.
Is there any way to override that so that it has an onclick event but
does not submit the form?

But of course
<input type="image" onclick="return doSomething();">

In function doSomething, make sure to return false to prevent the
default action (submit the form) is not carried out
 
B

bobzimuta

bobzimuta said:
<input type="image" onclick="return doSomething();">

Or, as I nearly forgot to mention,
<input type="image" onclick="doSomething(); return false">
in order to prevent having to explicitly return false in function
doSomething.
 
C

christopher.secord

bobzimuta said:
Or, as I nearly forgot to mention,
<input type="image" onclick="doSomething(); return false">
in order to prevent having to explicitly return false in function
doSomething.

Thanks for the tip. "return functionName()" I hadn't heard of that
one before.

chris
 

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

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top