Click here to Skip to main content
15,890,512 members
Home / Discussions / JavaScript
   

JavaScript

 
AnswerRe: Working example for Javascript to call a java webservice Pin
ZurdoDev2-Nov-12 11:04
professionalZurdoDev2-Nov-12 11:04 
GeneralRe: Working example for Javascript to call a java webservice Pin
Member 946160725-Nov-12 19:32
Member 946160725-Nov-12 19:32 
QuestionJS::Page a serious fault Pin
lsw52131425-Oct-12 21:14
lsw52131425-Oct-12 21:14 
AnswerRe: JS::Page a serious fault Pin
enhzflep27-Oct-12 9:57
enhzflep27-Oct-12 9:57 
QuestionFill a "2D" Array with random values Pin
0bx24-Oct-12 12:27
0bx24-Oct-12 12:27 
AnswerRe: Fill a "2D" Array with random values Pin
enhzflep26-Oct-12 20:52
enhzflep26-Oct-12 20:52 
QuestionFlexigrid Pin
chandra reinhart15-Oct-12 1:23
chandra reinhart15-Oct-12 1:23 
Questionpagination Pin
millekekez12-Oct-12 22:32
millekekez12-Oct-12 22:32 
hello
i would appreciate a little help here
is it possible to make default pagination of my dynamic html table created from saving form elements
i need to make 15 records per page and i tried lots of plugins but i couldn't get it done

thanks

Mille

my code is:
var Animals ={
index: window.localStorage.getItem("Animals:index"),
$table: document.getElementById("animals-table"),
$form: document.getElementById("animals-form"),
$button_save: document.getElementById("animals-save"),
$button_discard: document.getElementById("animals-discard"),

init: function() {
if (!Animals.index) {
window.localStorage.setItem("Animals:index", Animals.index = 1);
}
Animals.$form.reset();
Animals.$button_discard.addEventListener("click", function(event) {
Animals.$form.reset();
Animals.$form.id_entry.value = 0;
}, true);
Animals.$form.addEventListener("submit", function(event) {
var entry = {
id: parseInt(this.id_entry.value,radix),
animal_id:this.animal_id.value,
animal_name: this.animal_name.value,
animal_type: this.animal_type.value,
bday: this.bday.value,
animal_sex: this.animal_sex.value,
mother_name: this.mother_name.value,
farm_name: this.farm_name.value,
money: this.money.value,
weight: this.weight.value,
purchase_partner: this.purchase_partner.value

};
if (entry.id === 0) {
Animals.storeAdd(entry);
Animals.tableAdd(entry);
}
else { // edit
Animals.storeEdit(entry);
Animals.tableEdit(entry);
}

this.reset();
this.id_entry.value = 0;
event.preventDefault();
}, true);


if (window.localStorage.length - 1) {
var animals_list = [], i, key;
for (i = 0; i < window.localStorage.length; i++) {
key = window.localStorage.key(i);
if (/Animals:\d+/.test(key)) {
animals_list.push(JSON.parse(window.localStorage.getItem(key)));
}
}

if (animals_list.length) {
animals_list.sort(function(a, b)
{return a.id < b.id ? -1 : (a.id > b.id ? 1 : 0);})

.forEach(Animals.tableAdd);}
}

Animals.$table.addEventListener("click", function(event) {
var op = event.target.getAttribute("data-op");
if (/edit|remove/.test(op)) {
var entry = JSON.parse(window.localStorage.getItem("Animals:"+ event.target.getAttribute("data-id")));
if (op == "edit") {

Animals.$form.id_entry.value = entry.id;
Animals.$form.animal_id.value = entry.animal_id;
Animals.$form.animal_name.value = entry.animal_name;
Animals.$form.animal_type.value = entry.animal_type;
Animals.$form.bday.value = entry.bday;
Animals.$form.animal_sex.value = entry.animal_sex;
Animals.$form.mother_name.value = entry.mother_name;
Animals.$form.farm_name.value = entry.farm_name;
Animals.$form.money.value = entry.money;
Animals.$form.weight.value = entry.weight;
Animals.$form.purchase_partner.value = entry.purchase_partner;

}
else if (op == "remove") {
if (confirm('Are you sure you want to remove this animal from your list?' )) {
Animals.storeRemove(entry);
Animals.tableRemove(entry);
}
}
event.preventDefault();
}
}, true);
},

storeAdd: function(entry) {
entry.id = Animals.index;
window.localStorage.setItem("Animals:index", ++Animals.index);
window.localStorage.setItem("Animals:"+ entry.id, JSON.stringify(entry));
},
storeEdit: function(entry) {
window.localStorage.setItem("Animals:"+ entry.id, JSON.stringify(entry));
},
storeRemove: function(entry) {
window.localStorage.removeItem("Animals:"+ entry.id);
},

tableAdd: function(entry) {
var $tr = document.createElement("tr"), $td, key;
for (key in entry) {
if (entry.hasOwnProperty(key)) {
$td = document.createElement("td");
$td.appendChild(document.createTextNode(entry[key]));
$tr.appendChild($td);
}
}
$td = document.createElement("td");
$td.innerHTML = 'Edit | Remove';
$tr.appendChild($td);
$tr.setAttribute("id", "entry-"+ entry.id);
Animals.$table.appendChild($tr);
},
tableEdit: function(entry) {
var $tr = document.getElementById("entry-"+ entry.id), $td, key;
$tr.innerHTML = "";
for (key in entry) {
if (entry.hasOwnProperty(key)) {
$td = document.createElement("td");
$td.appendChild(document.createTextNode(entry[key]));
$tr.appendChild($td);
}
}
$td = document.createElement("td");
$td.innerHTML = 'Edit | Remove';
$tr.appendChild($td);
},
tableRemove: function(entry) {
Animals.$table.removeChild(document.getElementById("entry-"+ entry.id));
}
};

Animals.init();

</script>
QuestionProblem with IE 9 Pin
giocot11-Oct-12 7:21
giocot11-Oct-12 7:21 
AnswerRe: Problem with IE 9 Pin
Member 950758611-Oct-12 23:02
Member 950758611-Oct-12 23:02 
AnswerRe: Problem with IE 9 Pin
jkirkerx17-Oct-12 12:20
professionaljkirkerx17-Oct-12 12:20 
AnswerRe: Problem with IE 9 Pin
twseitex19-Oct-12 7:39
twseitex19-Oct-12 7:39 
Questionwindow.open not working inside frame in google chrome. Pin
Virjin Antony10-Oct-12 1:57
Virjin Antony10-Oct-12 1:57 
AnswerRe: window.open not working inside frame in google chrome. Pin
twseitex19-Oct-12 8:28
twseitex19-Oct-12 8:28 
AnswerRe: window.open not working inside frame in google chrome. Pin
saimimtiaz28-Oct-12 8:19
saimimtiaz28-Oct-12 8:19 
QuestionFileUpload Inside a Gridview ItemTemplate Pin
Member 79103609-Oct-12 19:25
Member 79103609-Oct-12 19:25 
AnswerRe: FileUpload Inside a Gridview ItemTemplate Pin
Mohibur Rashid9-Oct-12 21:22
professionalMohibur Rashid9-Oct-12 21:22 
AnswerRe: FileUpload Inside a Gridview ItemTemplate Pin
kavittrivedi16-Oct-12 2:29
kavittrivedi16-Oct-12 2:29 
QuestionFile Upload in IE Pin
ziggyfish9-Oct-12 15:26
ziggyfish9-Oct-12 15:26 
AnswerRe: File Upload in IE Pin
twseitex19-Oct-12 8:31
twseitex19-Oct-12 8:31 
Questionbitwise operator question Pin
SuperRoo29-Oct-12 13:19
SuperRoo29-Oct-12 13:19 
AnswerRe: bitwise operator question Pin
ziggyfish9-Oct-12 15:31
ziggyfish9-Oct-12 15:31 
Question“Object doesn't support property or method 'ready'” Pin
Rohit Kesharwani9-Oct-12 1:42
Rohit Kesharwani9-Oct-12 1:42 
AnswerRe: “Object doesn't support property or method 'ready'” Pin
Graham Breach9-Oct-12 20:55
Graham Breach9-Oct-12 20:55 
QuestionTried Typescript? What's your first impressions? Pin
StianSandberg5-Oct-12 2:01
StianSandberg5-Oct-12 2:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.