File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes Populating JSP text field with Javascript? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Populating JSP text field with Javascript?" Watch "Populating JSP text field with Javascript?" New topic
Author

Populating JSP text field with Javascript?

Chris Stann
Ranch Hand

Joined: Oct 10, 2006
Posts: 49
I have been trying to solve this for sometime now and it does not seem to work.

I have a text field defined in a jsp page:



I have this fancy Javascript function which searches a list and returns the result. Search is working fine. The result needs to show up in the above text field. The code below is supposed to make that happen:



searchlist.options[0].text contains the results of my search - I have verified this. classText.value does not seem to take the search result.

Help please?


EXCEL IN ALL YOU DO
Michael Ku
Ranch Hand

Joined: Apr 20, 2002
Posts: 510
I think that you need to have an id attribute not property attribute in your html:text tag. property is related to your Struts ActionForm property.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61413
    
  67

Assign an id to the field and use document.getElementById() to access it. This is the most staright-forward and accepted means to reference DOM elements.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61413
    
  67

Populating JSP text field
A point of clarification: there is no such thing as a "JSP text field". Regardless of how you specify it in a JSP, by the time it gets to the browser, it's just an HTML element like any other. To see what the Struts tag generated, do a View Source in the browser. This is what your JavaScript will be dealing with.
Chris Stann
Ranch Hand

Joined: Oct 10, 2006
Posts: 49
Thanks for the suggestions. I'll give it a try and post results.
Chris Stann
Ranch Hand

Joined: Oct 10, 2006
Posts: 49
Well, well, well... the code works.. In Internet Exploder! Argh... I was testing in Firefox.

Note to self: Always test using multiple browsers without assumptions of cross-compatibility.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Populating JSP text field with Javascript?