TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Kasuni Abegunawardana
NA
211
125.1k
How to Delete, Edit array items from Javascript
May 8 2018 11:35 PM
Hi, all, please take a look at this code and help me to complete this.
Thank you.
var
_students = [];
function
addStudent() {
var
lblMsgInfo = document.getElementById(
"labelMessageInfo"
);
lblMsgInfo.innerHTML =
""
;
if
(isFormValid()) {
var
regnum = document.getElementById(
"textboxRegistrationNumber"
).value;
var
newStudent = {
RegNum: regnum
};
_students.push(newStudent);
var
ul = document.getElementById(
"listStudents"
);
var
li = document.createElement(
"li"
);
li.appendChild(document.createTextNode(newStudent.RegNum ));
ul.appendChild(li);
//alert('Student added successfully to the list');
lblMsgInfo.innerHTML =
"Student added successfully to the list"
;
}
}
function
isFormValid() {
//Validate form
var
lblMsg = document.getElementById(
"labelMessageError"
);
lblMsg.innerHTML =
""
;
var
regnum = document.getElementById(
"textboxRegistrationNumber"
).value;
if
(regnum.length == 0) {
lblMsg.innerHTML =
"Registration number is required"
;
return
false
;
}
else
if
(isRegnumalreadyExist(regnum)) {
lblMsg.innerHTML =
"Registration number already exist"
;
return
false
;
}
return
true
;
}
function
isRegnumalreadyExist(regNum) {
for
(
var
i = 0; i < _students.length; i++) {
if
(_students[i].RegNum == regNum)
return
true
;
}
return
false
;
}
// Clear Function
function
resetform() {
document.getElementById(
"myform"
).reset();
}
//Delete Function
function
DeleteRecord() {
}
Reply
Answers (
3
)
How to store jsondata in combobox ?
How to update Array and Display in a Table in javascript