This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Struts and the fly likes Getting the values of a dynamic(javascript) HTML Select Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Getting the values of a dynamic(javascript) HTML Select" Watch "Getting the values of a dynamic(javascript) HTML Select" New topic
Author

Getting the values of a dynamic(javascript) HTML Select

Timothy Sam
Ranch Hand

Joined: Sep 18, 2005
Posts: 746
Hi guys

It's been a while since I've used Struts.

I happen to have two html:select elements, A and B respectively. They are both of type String[] in my ActionForm.

Now, A gets poppulated dynamically by me by iterating through a request variable (a List, actually).

B initially doesn't have any values, its values are dynamically generated through Javascript. Basically, B gets its option elements from A using Javascript.

Now, when I get to my Action class, I get a NullPointerException. It seems that B doesn't get its value at all although I am setting the property for it. Here are some code snippets.

Please excuse my caps, they're not meant to mean that I'm shouting.



Is it important the I set the <option> tag's ID or Name attribute in plain old HTML during the Javascript process? Thanks!


SCJP 1.5
http://devpinoy.org/blogs/lamia/ - http://everypesocounts.com/
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8843
    
    7

This is an HTML oddity. Select fields are intended to display a list of items and one picks the values they wanted by selecting one or more. What you want to do is submit all the values in a particular select field. The solution is to use javascript to select all the values in that field before submitting the form.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting the values of a dynamic(javascript) HTML Select
 
Similar Threads
add values in select option using ajax and servlet
Struts and javascript
How to populate html:select
/html:select multiple="true"/ problem while editing page
adding dynamic controls in struts2