• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JSP and JavaScript form question

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi.

I'm having a simple problem - I need to have a text field and a button near it so I can post some info. I am using JSP (Struts to be exact) in combination with JavaScript. JS is mostly for nice rollover effects.

The problem is that I don't know how to set up my custom button inside my form. My buttons are all in a row (table-row) and all of them are made from <html:link> element with a nested <img> element. <html:link> calls the appropriate rollover JS functions and the <img> defines a name to be used. Simple.

However my button for info posting should be in a form so <html:link> cannot be used (as far as I know). Now the headache begins. If I use an <html:image> tag inside a form I cannot set the name and my JS rollover functions don't work. But that's not all. The button is (for some reason) misaligned with the other buttons.

I would like my submit button to be OUTSIDE a form since than I can define it inside a <html:link> button and it will be neatly aligned with the other buttons. Can somebody please tell me how do read the contents of a textfield from this element ? Or at least explain why is that misaligment happening and suggest how to solve it? Thanks.

(Btw my code is simmilar to the one used in IncludeTop.jsp page in the JPetstore application which I used as a learning tool. Anyway, you can check it out there if I wasn't too clear with what I wanted)
[ May 05, 2005: Message edited by: Mortimer Mousse ]
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If your button is outside of the form, you can still cause it to submit the form via Javascript. For example you could make the onclick handler:

 
Mortimer Mousse
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, that's just what I needed.

But how do I name the form? <html:form> tag doesn't allow names...
 
Ranch Hand
Posts: 489
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


But how do I name the form? <html:form> tag doesn't allow names...



In which case use the forms array to access the form object. Javascript allows the use of either the form name or the form array to retrieve a handle to the form object.

If your page contains two forms (say) and you wish to get a handle to the first and then call submit on it,



will do the work for you.

Cheers,
Ram.
 
Did you miss me? Did you miss this tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic