• 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

Populating JSP text field with Javascript?

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
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
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
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

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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the suggestions. I'll give it a try and post results.
 
Chris Stann
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic