<script type="text/javascript" src="js/json2.js"></script>
<script type="text/javascript">
var appInc = 0;
var rowInc = 0;
var On_Error = false;
function addRow(r){
var root = r.parentNode;//the root
var allRows = root.getElementsByTagName('tr');//the rows' collection
var cRow = allRows[0].cloneNode(true)//the clone of the 1st row
var cInp = cRow.getElementsByTagName('asp:TextBox');//the inputs' collection of the 1st row
for(var i=0;i<cInp.length;i++) {//changes the inputs' names (indexes the names)
cInp[i].setAttribute('name',cInp[i].getAttribute('name')+'_'+(allRows.length+1))
}
root.appendChild(cRow);//appends the cloned row as a new row
}
function addAppartement() {
appInc++;
var appTable = document.getElementById("appTable");
var a = document.createElement('div');
a.setAttribute("id", "a" + appInc);
appTable.appendChild(a);
var html = '<form name="form' + appInc + '" action="#">\n';
html += '<table>\n';
html += '<tr>\n';
html += '<td class="td" vAlign="top" align="center" width="60"><input id="txtAppNr' + appInc + '" style="width: 44px" type="text"></td>\n';
html += '<td class="td" vAlign="top" align="center" width="50"><input id="txtFloor' + appInc + '" style="width: 44px" type="text"></td>\n';
html += '<td class="td" vAlign="top" align="center" width="50"><input id="txtUnitPlac' + appInc + '" style="width: 43px" type="text"></td>\n';
html += '<td class="td" vAlign="top" align="center" width="115"><input id="txtConsID' + appInc + '" style="width: 104px" type="text"></td>\n';
html += '<td class="td" vAlign="top" align="center" width="90"><input id="txtUnitNr' + appInc + '" style="width: 74px" type="text"></td>\n';
html += '<td class="td" vAlign="top" align="center" width="90"><input id="txtUnitSet' + appInc + '" style="width: 74px" type="text"></td>\n';
html += '<td class="td" vAlign="top" align="center" width="50"><input id="txtFuse' + appInc + '" style="width: 44px" type="text"></td>\n';
html += '<td class="td" vAlign="top" align="center" width="135"><input id="txtCustomer' + appInc + '" style="width: 120px" type="text"></td>\n';
html += '<td class="td" vAlign="top" align="center" width="135"><input id="txtDOB' + appInc + '" style="width: 120px" type="text"></td>\n';
html += '<td class="td" vAlign="top" align="center" width="20"> </td>\n';
html += '</tr>\n';
html += '</table>\n';
html += '</form>';
a.innerHTML = html;
document.forms[0].txtNrFlats.value = appInc;
}
function removeAppartement(appID) {
appInc--;
var d = document.getElementById('appTable');
var olddiv = document.getElementById('a' + appID);
d.removeChild(olddiv);
document.forms[0].txtNrFlats.value = appInc;
}
function SendForm() {
var regid = document.getElementById("txtRegistrationID").value;
var unitplace;
for (i = 0; i < document.forms[0].rdbUnitPlace.length; i++) {
if (document.forms[0].rdbUnitPlace[i].checked) {
unitplace = document.forms[0].rdbUnitPlace[i].value;
}
}
var nrapps = document.getElementById("txtNrFlats").value;
var city = document.getElementById("txtCity").value;
var date = document.getElementById("txtDate").value;
var installer = document.getElementById("txtInstaller").value;
if (nrapps == '' || nrapps == '0') {
document.getElementById('response').innerHTML = 'Du måste ange minst en lägenhet för att registreringen ska genomföras';
return;
}
<hidden>.multihousereg.DoStoringEvent(regid,unitplace,nrapps,city,date,installer,ServerSide_Callback);
if (On_Error == true) { return; }
var i = 0;
var arrSize = Number(nrapps);
var arrApps = new Array(arrSize );
for (i = 0; i < arrSize; i++) {
arrApps[i] = new Array(9);
}
var o = objectify();
var jsonString = JSON.stringify(o);
alert(jsonString);
//<hidden>.multihousereg.PopulateAppartements2(jsonString,ServerSide_Callback2);
//window.location = "https://www.a_web_server.se/<folder>/regThanks.aspx?op=multiReg";
}
function objectify() {
var o = {};
var frms = document.forms;
var formID = 1;
var id = 1;
for (i = 0, maxI = frms.length; i < maxI ; i++) {
if (frms[i].name == 'form' + formID) {
var frm = frms[i];
var elms = frm.elements;
var tmp = {};
for (var j = 0, maxJ = elms.length; j < maxJ; j++) {
var el = elms[j];
tmp[el.name] = el.value;
}
o[frm.name] = tmp;
formID++;
}
}
return (o);
}
function ServerSide_Callback(response) {
if (response.error != null) {
document.getElementById('response').innerHTML += response.error.value + '<br>';
On_Error = true;
return;
}
}
function ServerSide_Callback2(response) {
if (response.error != null) {
document.getElementById('response').innerHTML += response.error + '<br>';
On_Error = true;
return;
}
}
</script>