Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I use image to submit form onClick? 1

Status
Not open for further replies.

casabella

Programmer
Aug 30, 2007
59
US
I am writing a search form. There are several fields the user will be able to use to search. I want to:

1) create a single form
2) associate an image to each field which onclick, submits form

Does not sound complicated at all ... I just cannot get it to work. I have tried

Code:
<img .... onClick="submit()" ... >
<img .... onClick="document.FormName.submit()" ... >
<a href="javascript: document.FormName.submit()" ...><img ...></a>

every one of them gives me an error - They all say that submit is not a function. I am using FireFox.

Thank you all for you help!


Jose


 
You should use an "image" input. Not only is this tied to to the form, but you won't need to have JavaScript enabled to use it. E.g.:

Code:
<form ...>

   <div>
      <input type="text" ... />
      <input type="image" src="whatever.gif" />
   </div>

   <div>
      <input type="text" ... />
      <input type="image" src="whatever.gif" />
   </div>

</form>

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Incidentally, you are probably seeing the error because you have a form element named "submit". The JS engine doesn't know whether you are referring to the form element named submit, or the form object's method named submit.

You can get around this by renaming your "submit" element. Or better still go with the image method I mentioned in my previous post.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
BillyRay,

Yes, you were right on the money!

I did not want to use multiple forms but I ended-up doing so after all. It works well. I added hidden fields to hold what I intended to plug in the URL using onclick() and all is great.

Thanks,

Jose

PS: I had not come back to the forum since I recently started a new job and have been very busy getting in the loop of this. Your post, as usual, is greatly appreciated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top