JavaScript and Forms/Images - Image buttons

They have: 5,633 posts

Joined: Jan 1970

I'm currently using images as buttons for some forms I'm developing. Does anyone know how to make such a button the default (ie hit 'enter' and have form submit)? Thanks in advance for you replies...

They have: 5,633 posts

Joined: Jan 1970

Here is the code to have the button appear as an image. As for the submit part, I'm not to sure about it. You would use the "onClick" event handler. I'm sure someone will help you with the code.

<form>

<input type="image" src="URL">

</form>

----------
[email protected]
vegas.com.au/~jasper

They have: 99 posts

Joined: May 1999

The submit part is handled by javascript submit() function. Example:
set your form somewhere in the code (if you want to use buttons, they will need to be in the form. You can use images then you can put the form anywhere else in the doc if you choose)
<FORM NAME="my_form" METHOD="POST" ACTION="/cgi-bin/process_form.cgi"
TARGET="some_frame">
</form>

Set up your image(I prefer them, but you can do the same w/ a button)

<A HREF="#" ONCLICK="my_function();"
<IMG NAME="my_graphic" SRC="graphics/abc.gif" WIDTH="50" HEIGHT="50" BORDER="0"></A>

Then in your function you can do whatever you want (validate data, close a window, open a window, etc) and when you are ready just do:

document.my_form.submit();

The nice thing about submitting the form this way is that you can do it from other frames/windows etc.... Good luck.

----------
Alan Izat

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.