Location: PHPKode > projects > HypatiaDB > hypatiadb/js/tblCFuncs.php
<?php header("Content-Type: text/javascript");
include('../common_db.php');
include('../functions.php');
dbconnect($host, $username, $password);

$strings = loadStrings($lang, 'TBLC1');
?>

function addField() {
	var dst = document.getElementById('dst');
	var src = document.getElementById('src');
	var copy = src.cloneNode(true);
	var count = parseInt(document.getElementById('fieldcount').getAttribute('value'));
	copy.id = 'p' + count;


	var remspan = document.createElement('span');
	remspan.setAttribute('class', 'll');
	remspan.onclick = removeNode;
	remspan.appendChild(document.createTextNode(' [<?php echo($strings['TBLC_1_REMOVE']); ?>]'));
	copy.appendChild(remspan);

	fixIdsAndNames(copy, count);

	dst.appendChild(copy);
	document.getElementById('fieldcount').setAttribute('value', count + 1);
}

function fixIdsAndNames(e, cnt) {
	//this also sets validation functions
	for(var i = 0; i < e.childNodes.length; i++) {	//>
		if(e.childNodes[i].nodeName == "label") {
			var n = e.childNodes[i].getAttribute('for');
			e.childNodes[i].setAttribute('for', n.substring(0, n.length - 1) + cnt);
			fixIdsAndNames(e.childNodes[i], cnt);
		} else if (e.childNodes[i].nodeName == "input") {
			//set validation function
			setValidationFunc(e.childNodes[i]);

			//fix ids and names
			var n = e.childNodes[i].getAttribute('name');
			e.childNodes[i].setAttribute('name', n.substring(0, n.length - 1) + cnt);
			if(e.childNodes[i].getAttribute('id'))
				e.childNodes[i].setAttribute('id', n.substring(0, n.length - 1) + cnt);
		} else if (e.childNodes[i].nodeName == "select") {
			var n = e.childNodes[i].getAttribute('id');
			e.childNodes[i].setAttribute('name', n.substring(0, n.length - 1) + cnt);
			e.childNodes[i].setAttribute('id', n.substring(0, n.length - 1) + cnt);
		} else if (e.childNodes[i].nodeName == "div" || e.childNodes[i].nodeName == "td") {
			var n = e.childNodes[i].getAttribute('id');
			if(n)
				e.childNodes[i].setAttribute('id', n.substring(0, n.length - 1) + cnt);
			fixIdsAndNames(e.childNodes[i], cnt);
		}
	}
}

function removeNode() {
	this.parentNode.parentNode.removeChild(this.parentNode);
	var count = parseInt(document.getElementById('fieldcount').getAttribute('value'));
	document.getElementById('fieldcount').setAttribute('value', count - 1);
}

function checkPri() {
	document.getElementById('pkwarning').style.display = "none";
}
Return current item: HypatiaDB