0

In my rails application, i have a form where user has to select some items via checkbox. I want to display the selected items' information in a div.

I am currently using javascript to do that.

So in form, when user clicks in a checkbox, i pass the 'this' obj as parameter to a javascript function which then appends the 'this.value' to the end the div.

However appending the 'this.value' displays only the id of of the selected item. I also want to display the other data of the selected item in the div.

Is that possible in javascript? How do i get other information of the 'this' obj, apart from 'this.value'?

Many thanks for any suggestion provided.

Please find code below-

#in my form:
<input id="id_<%= item.id %>" name="submission[item_ids][]" onclick="addtoselected(this);" value="<%= item.id %>" type="checkbox" />

javascript code:

function addtoselected(obj){
    if(obj.checked==true){
    var s = '<div>' + obj.value + '</div>';
    $j('#selected_recs').append(s);
    }
}
1
  • 1
    Put up some code that you have so far. Preferably on jsfiddle.net. It's hard to understand what you are asking. Commented May 3, 2011 at 23:00

2 Answers 2

1

If the text you want is in a label, you could loop through all labels and check which one has the id in his for attribute.

Sign up to request clarification or add additional context in comments.

Comments

1

Use the contents of this.value to lookup the information you need. You could send it as a parameter to a server-side script to get its information back in JSON format, or if you already have an existing javascript object store, you could look up the item's information from there.

1 Comment

Thanks for the suggestion..will have a look at JSON and try using it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.