posted 11 years ago
hi,
i had done validation by using Ajax..it is working fine..the problem...if i enter another value it is not getting added to xml file...can any one check it and help me out..waiting for the reply...here is the code...
function validate() {
if (document.frm.id.value == "") {
alert("Enter Package Name");
document.frm.id.focus();
return (false);
}
chkId = /^[WAP_]{4}\d{2}$/;
if (chkId.test(document.frm.id.value)) {
} else {
alert('Invalid \"Pack Name\" Entry');
return false;
}
if (document.frm.act.value == "") {
alert("Enter Activation Status");
document.frm.act.focus();
return (false);
}
chkAct = /^[MA]{2}\d{2}$/;
if (chkAct.test(document.frm.act.value)) {
} else {
alert('Invalid \"Activation Status\" Entry');
return false;
}
if (document.frm.deact.value == "") {
alert("Enter De-Activation Status");
document.frm.deact.focus();
return (false);
}
chkDeact = /^[MD]{2}\d{2}$/;
if (chkDeact.test(document.frm.deact.value)) {
} else {
alert('Invalid \"De-Activation Status\" Entry');
return false;
}
if (document.frm.allwpp.selectedIndex < 0) {
alert("Select one of the \"Allow Post-Paid or Not\" options.");
document.frm.allwpp.focus();
return (false);
}
if (document.frm.allwpp.selectedIndex == 0) {
alert("Select \"Allow Post-Paid or Not\" option.");
document.frm.allwpp.focus();
return (false);
}
if (document.frm.shrt.value == "") {
alert("Enter Package Name");
document.frm.shrt.focus();
return (false);
}
return true;
}
function trim(stringToTrim) {
return stringToTrim.replace(/^\s+|\s+$/g, "");
}
var xmlHttp = null;
function login() {
if (validate()) {
try {
// Firefox, Opera 8.0+, Safari
xmlHttp = new XMLHttpRequest();
} catch (e) {
// Internet Explorer
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}
var id = document.getElementById("id").value;
var url = "/xmlgprs/login.xml";
url = url + "?id=" + id;
xmlHttp.onreadystatechange = stateChanged;
xmlHttp.open("GET", url, true);
xmlHttp.send(null);
}
}
function stateChanged() {
if (xmlHttp.readyState == 4) {
if (xmlHttp.status == 200) {
parseMsg();
} else {
alert("Unable to retrieve");
}
}
}
function trim(stringToTrim)
{
return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function parseMsg() {
var id = document.getElementById("id").value;
response = xmlHttp.responseXML.documentElement;
var node = response.getElementsByTagName("PACK_NAME");
//Na=Node();
//Na.toString()
// alert(node.length)
//ele=Element()
//ele.nodeValue
for ( var i = 0; i < node.length; i++) {
var node1 = node.item(i);
var childNodes=node1.childNodes;
for ( var j = 0; j < childNodes.length; j++) {
var childNode=childNodes.item(j);
if(childNode.nodeType == Node.TEXT_NODE){
alert(childNode.nodeValue);
if(trim(childNode.nodeValue) == trim(id)){
alert("already Present");
break;
}
}
}
//idArray[i] = node1.text;
}
}
Thanks in advance,
madhu.