wood burning stoves 2.0*
The moose likes Struts and the fly likes Javascript - Arraylist Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Javascript - Arraylist" Watch "Javascript - Arraylist" New topic
Author

Javascript - Arraylist

Luke Zechariah
Ranch Hand

Joined: Sep 27, 2005
Posts: 117
Please help, I am trying to accomplish 2 things:

1. I am having a list of objects, how do I get the values into the javascript. Suppose I have 5 rows, if I check on the 3rd checkbox, how do I send the values to javascript.
2. I also want to check only one check box at a time, how do I accomplish, ie. if I check the left one, the right one needs to be unchecked automatically.


Example:


Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61095
    
  66

Please take the time to choose the correct forum for your posts. This is the second post of yours today that I've moved to the Struts forum. For more information, please read this.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Luke Zechariah
Ranch Hand

Joined: Sep 27, 2005
Posts: 117
I'm sorry sheriff.
Er. Rohit Sharma
Greenhorn

Joined: Dec 11, 2008
Posts: 16
As per my understanding your jsp will some what look like this :

checkbox property1 property2 property3 property4 checkbox.

Are you provinding distinct id's to each row so that the row can be differentiated from other row.
Or you can also provide different id's to each property of jsp.
If you are succeded in doing this then all you have to do is.. document.getElementById(unique id).value;
if you get the id then you can disable the other checkbox by setting its value to false.
Luke Zechariah
Ranch Hand

Joined: Sep 27, 2005
Posts: 117
Thanks Rohit,

No I am not providing distinct id to each row. The jsp does not allow me to assign id's, it is giving me error How can I achieve that functionality. Please let me know.

Here is what I have written:

<td><html:multibox id="acpt" property="arIndexVal" onclick="populateList(this, 'A')" >
<bean:write name="item" property="acceptValues" />
</html:multibox></td>

It is giving errors when I write the id="acpt".

Thanks,
Lk.
Rohit Sharad Sharma
Greenhorn

Joined: Jan 14, 2010
Posts: 6
Use styleId in place of id.
Luke Zechariah
Ranch Hand

Joined: Sep 27, 2005
Posts: 117
Thanks Rohit, it is working.

I have 2 more questions:

1. What is the equivalent of checked="checked" in multibox because when the page loads all the check boxes are checked. I want them to be unchecked.

2. Ok I got the value to the javascript. Appended it with a string, now how do I pass it back to the form and add it to the javabean. Is it possible. All I want to know is which checkbox I choose, the left one or the right one.
Rohit Sharad Sharma
Greenhorn

Joined: Jan 14, 2010
Posts: 6
Luke you can have a look at struts api , there you would be able to find each tag associated with multibox. Try and have a look.

And for setting the value back to bean use document.forms[0].property.value = your value;
and for submitting use document.form.submit();
Do take care your jsp should hold a property name against the value you are submitting and if not use hidden fields as a value holder.
Luke Zechariah
Ranch Hand

Joined: Sep 27, 2005
Posts: 117
Thanks Rohit,

I found a way how to keep the checkboxes unchecked while displaying. We need to define the reset method in the form as below:

In the action file call the function:
concurrentCaseInfoForm.reset(mapping, request);


I have another question: please see below code:
JSP:


The notes field at the bottom is a html:text field, so if I change anything in the text field on the jsp, it should store in the form. But when called in the action I am getting a null value. In the action I am calling it as:




I am getting the output having null objects for the bean.

Please let me know, hope I am clear with my question i.e. How do I store the values in the bean if there is any change on the jsp.

Thanks,
Lk.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Javascript - Arraylist