File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Populating JSP text field with Javascript?

 
Chris Stann
Ranch Hand
Posts: 49
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Michael Ku
Ranch Hand
Posts: 510
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64178
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64178
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 49
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the suggestions. I'll give it a try and post results.
 
Chris Stann
Ranch Hand
Posts: 49
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic