aspose file tools*
The moose likes JSP and the fly likes JSP and JavaScript form question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP and JavaScript form question" Watch "JSP and JavaScript form question" New topic
Author

JSP and JavaScript form question

Mortimer Mousse
Greenhorn

Joined: Apr 13, 2005
Posts: 6
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 ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61652
    
  67

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:



[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Mortimer Mousse
Greenhorn

Joined: Apr 13, 2005
Posts: 6
Thanks, that's just what I needed.

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

Joined: Jan 24, 2005
Posts: 489


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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP and JavaScript form question