• 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

Pass selected bean property to javascript

 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Everyone,

I have the following on a JSP:



What I'd like to do is pass the filePath property of the currently selected bean (critTone) in the select list to the playTone() javascript. I'm having a hard time trying to get my head around what the best approach would be since I'm not refrencing the option value. The way it is written above, the value being passed to the playTone() function is the filePath of the last bean in the iteration.

This has to be a fairly common thing to do... does anyone have any suggestions?

Thanks!
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd suggest using server-side code that loops through your list and creates a JavaScript associative array containing tone Ids and their corresponding paths. In case you're not familiar with it, an associative array in JavaScript works very much like a HashMap in Java. Below, I've hard-coded an example of what the array would look like when it's rendered:



Then you can get the path with this line:

var path = tonesAndPaths[document.myForm.criticalAlertId.value];
[ August 03, 2006: Message edited by: Merrill Higginson ]
 
Brian R. Wainwright
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Merrill,

I came up with an idea that was similar to your implementation using a javascript array, but it runs on the client...



And then elsewhere on my jsp...



So when the page laods, I iterate through my list and populate a Javascript array with the values I need to retrieve. In my hyperlink, I call playTone() whcih takes the name of the particular element. I then get the selected index of that element and based on that look up the value by index in my prepopyulated array. Works great.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic