This kind of thing is exactly that I have, and the push and splice is working marvellously. But I want to add(push) items when I click on some sort of button.
Like:
Button click... data.items.push(anything)... and it appears in the list (the array which I am using like a list).
Link
Asked
Active
Viewed 5,305 times
-3
-
Use the `click` handler on the `button` element...? I'm not sure exactly what your'e asking here as the question is lacking a lot of detail about your specific problem. – Rory McCrossan Jul 31 '13 at 11:29
-
@rory dont -ve repute me! – InVaDeR Jul 31 '13 at 12:44
-
I didnt, but it appears others have. – Rory McCrossan Jul 31 '13 at 13:15
1 Answers
0
Enter move and type into the input boxes and then click the button, this will add the movie and type and unique ID in the object.
var data = {items: [
{id: "1", name: "Snatch", type: "crime"}
]};
$('button').on('click',function(){
var name = $('#name').val();
var type = $('#type').val();
var id = parseInt(data.items[data.items.length-1].id)+1;
data.items.push({"id":id.toString(), "name":name,"type":type});
console.log(data);
});

Anton
- 32,245
- 5
- 44
- 54
-
sorry, but its not DOING anything. Can u also display it please. also add the comment at the starting of the part of the code where it is just displaying, 'cause i have that figured out. – InVaDeR Jul 31 '13 at 11:48
-
@user2152309 Look in the console everytime you click the button and you will see the object will be added in the array – Anton Jul 31 '13 at 11:50
-
by console u mean where it is displaying code? because i'm not getting anything! and i want to display it in the screen because the array i am using is like... a playlist – InVaDeR Jul 31 '13 at 12:00
-
@user2152309 so you want something like this? http://jsfiddle.net/XYVaA/ – Anton Jul 31 '13 at 12:04
-
yes yes yes just i want to add things to list by the click of a button. and for the next time pls tell me firest that u are working on my answer, i dont really have patience i need to see a therapist!!! – InVaDeR Jul 31 '13 at 12:08
-
-
-
You click the arrow up on the left side of the answer and click the check mark under the arrow, 16 is not old :) – Anton Jul 31 '13 at 12:18
-
-
good thing that you have used push. Just one more thing, as i said i want to use it as a playlist, im combining it with this:http://www.beyondhyper.com/jplayer/. This guy also uses jso but when i asked him how to add songs, he didn't take interest. You think my thing will work with his playlist? – InVaDeR Jul 31 '13 at 12:30
-
-
-
-
Well if you want to have the things you've added to show next time you enter the website you need to save the array to sql or text file etc. – Anton Jul 31 '13 at 12:42
-
oooohhh. i thought that. Can you teach me pls? im not boring you am i? – InVaDeR Jul 31 '13 at 12:43
-
-
k you have been of gr8 help bye! when i post that question, is there any way to notify you? – InVaDeR Jul 31 '13 at 12:46
-
-