• 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

Need Javascript code to populate a field with one value from a list of values

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Hope all are doing well.
Could u please provide me with Javascript code or a link which has the code to populate a non-editable textfield with one value from a list of values. The code should be executed as part of onChange() Javascript method. Should pass the list of values as an argument to the method.
Thanks for your time.
Venkat
 
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi venkat

i am not all that clear with what the application but based on some assumptions I can say the following:
let the name of Form=FORM1
name of textfield=TEXT1
name of list=LIST1

so in your list you can put the onChange that will call a javascript function with the list value as parameter such as


for accessing the combo box value you need to use
this[this.selectedIndex].text..

then you may write




try it out. hope it helps.
 
Venkat Guduri
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Thanks a lot Niki.
Actually what I need is:
I have two columns in a table. Occupation, OccupationRating.
OccupationRating has corresponding rating for each Occuation.
Occupation is implemented as Combobox and when user selects any option, the corresponding Occupationrating has to be retrieved from the table (for eg: two dimentional array) and need to show up in a noneditable textfield.

The table is retrieved from database and have it in my JSP. Now I want to send the table(2 dim array) and selected option as arguments to Javascript method which will choose the corresponding rating from the table for the selection and updates the value. Can u please help to make it works.
Thanks for your time and patience.
 
Niki Nono
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have an idea which is not exactly the way you are looking for
ie:- not by retriving values into a two dimensional array and send to javascript.

but check this out.

you must be populating the combo box in java using the database right??

well considering thats the case for each entry in the combo box
you must be creating


or something like that.
well wy dont you assign the rating to the name attribute of the option tag as



assuming the rating for engineer is 1.
you will have to do this when you build the option tag in java.

this way every information is there in the combo box ie:- the occupation as well as the rating. no need for the array.
then in javascript you can very well access this value by
"this[this.selectedIndex].name" and the method i had pointed out to you earlier.
use both the steps properly and i know you will succeed.

i havent tried this out but i am preety sure it will work out.
try it out and let me know.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic