Jump to content

[Solved] How to get rid of "undefined" before table?


rain13
 Share

Recommended Posts

Hello. Introduction:I am trying to make JS that would generate nice tabbed table based on permissions array. Every PermissionClass (user, moderator, administrator, forum) should have it's own tab to divide permissions into logic groups. Problems:1)For some reason I get undefined<table cellspacing="2" cellpadding="2" border="1"><tbody> instead of<table cellspacing="2" cellpadding="2" border="1"><tbody> . Does anyone know what causes it and how I could fix that?Array Tables is generated dynamically.... is it because of that? 2)Other question I have is about tabs. When I switch between tabs JS forgets radio boxes checked status. I use function "SetTab" to handle tab switching. For example if I select "yes" for U_VIEWPROFILES (it's on {TAB1}) and then switch to {TAB2} and then back to {TAB1} then U_VIEWPROFILES doesn't have "yes" option selected anymore. How can I make JS remember what I've checked? Note:Before you can see contents of any tab you muct click on tab.

<html><head><STYLE TYPE="text/css"> li.Selected {	position: relative;	top: 1px;	background-color: #dbedff;} li.NotSelected {	position: relative;	top: 1px;	background-color: #99ccff;} #header ul {	list-style: none;	padding: 0;	margin: 0;} #header li {	float: left;	border: 1px solid #307C99;	border-bottom-width: 0;	margin: 0 1 0 0;} #content {	border: 1px solid #307C99;	clear: both;	background-color: #dbedff;}</STYLE></head><body><script type="text/javascript">var i;var Permissions = [];Permissions[0] = [];Permissions[0]["PermissionID"] = "1";Permissions[0]["PermissionClass"] = "user";Permissions[0]["Name"] = "U_VIEWPROFILES";Permissions[0]["Founder"] = "0";Permissions[1] = [];Permissions[1]["PermissionID"] = "2";Permissions[1]["PermissionClass"] = "user";Permissions[1]["Name"] = "U_IGNOREFLOOD";Permissions[1]["Founder"] = "0";Permissions[2] = [];Permissions[2]["PermissionID"] = "3";Permissions[2]["PermissionClass"] = "user";Permissions[2]["Name"] = "U_DOWNLOADFILES";Permissions[2]["Founder"] = "0";Permissions[3] = [];Permissions[3]["PermissionID"] = "4";Permissions[3]["PermissionClass"] = "user";Permissions[3]["Name"] = "U_ATTACH";Permissions[3]["Founder"] = "0";Permissions[4] = [];Permissions[4]["PermissionID"] = "5";Permissions[4]["PermissionClass"] = "user";Permissions[4]["Name"] = "U_USESIG";Permissions[4]["Founder"] = "0";Permissions[5] = [];Permissions[5]["PermissionID"] = "6";Permissions[5]["PermissionClass"] = "user";Permissions[5]["Name"] = "U_VIEWPROFILE";Permissions[5]["Founder"] = "0";Permissions[6] = [];Permissions[6]["PermissionID"] = "7";Permissions[6]["PermissionClass"] = "user";Permissions[6]["Name"] = "U_EDITOWNPROFILE";Permissions[6]["Founder"] = "0";Permissions[7] = [];Permissions[7]["PermissionID"] = "8";Permissions[7]["PermissionClass"] = "user";Permissions[7]["Name"] = "U_CANUSEAVATAR";Permissions[7]["Founder"] = "0";Permissions[8] = [];Permissions[8]["PermissionID"] = "9";Permissions[8]["PermissionClass"] = "user";Permissions[8]["Name"] = "U_CHANGEDEFAULTGROUP";Permissions[8]["Founder"] = "0";Permissions[9] = [];Permissions[9]["PermissionID"] = "10";Permissions[9]["PermissionClass"] = "moderator";Permissions[9]["Name"] = "M_APPROVEPOSTS";Permissions[9]["Founder"] = "0";Permissions[10] = [];Permissions[10]["PermissionID"] = "11";Permissions[10]["PermissionClass"] = "moderator";Permissions[10]["Name"] = "M_MANAGEBANS";Permissions[10]["Founder"] = "0";Permissions[11] = [];Permissions[11]["PermissionID"] = "12";Permissions[11]["PermissionClass"] = "moderator";Permissions[11]["Name"] = "M_MOVEPOSTS";Permissions[11]["Founder"] = "0";Permissions[12] = [];Permissions[12]["PermissionID"] = "13";Permissions[12]["PermissionClass"] = "moderator";Permissions[12]["Name"] = "M_CHANGEPOSTAUTHOR";Permissions[12]["Founder"] = "0";Permissions[13] = [];Permissions[13]["PermissionID"] = "15";Permissions[13]["PermissionClass"] = "moderator";Permissions[13]["Name"] = "M_EDITPOSTS";Permissions[13]["Founder"] = "0";Permissions[14] = [];Permissions[14]["PermissionID"] = "16";Permissions[14]["PermissionClass"] = "moderator";Permissions[14]["Name"] = "M_DELETEPOSTS";Permissions[14]["Founder"] = "0";Permissions[15] = [];Permissions[15]["PermissionID"] = "17";Permissions[15]["PermissionClass"] = "moderator";Permissions[15]["Name"] = "M_VIEWPOSTDETAILS";Permissions[15]["Founder"] = "0";Permissions[16] = [];Permissions[16]["PermissionID"] = "18";Permissions[16]["PermissionClass"] = "moderator";Permissions[16]["Name"] = "M_LOCKPOSTS";Permissions[16]["Founder"] = "0";Permissions[17] = [];Permissions[17]["PermissionID"] = "19";Permissions[17]["PermissionClass"] = "moderator";Permissions[17]["Name"] = "M_CLOSEREPORTS";Permissions[17]["Founder"] = "0";Permissions[18] = [];Permissions[18]["PermissionID"] = "20";Permissions[18]["PermissionClass"] = "moderator";Permissions[18]["Name"] = "M_ISSUEWARNING";Permissions[18]["Founder"] = "0";Permissions[19] = [];Permissions[19]["PermissionID"] = "21";Permissions[19]["PermissionClass"] = "administrator";Permissions[19]["Name"] = "A_GROUPGroupPermissions";Permissions[19]["Founder"] = "0";Permissions[20] = [];Permissions[20]["PermissionID"] = "22";Permissions[20]["PermissionClass"] = "administrator";Permissions[20]["Name"] = "A_MANAGEBANS";Permissions[20]["Founder"] = "0";Permissions[21] = [];Permissions[21]["PermissionID"] = "23";Permissions[21]["PermissionClass"] = "administrator";Permissions[21]["Name"] = "A_DEFINEBBCODE";Permissions[21]["Founder"] = "0";Permissions[22] = [];Permissions[22]["PermissionID"] = "24";Permissions[22]["PermissionClass"] = "administrator";Permissions[22]["Name"] = "A_MANAGEBOARDSETTINGS";Permissions[22]["Founder"] = "0";Permissions[23] = [];Permissions[23]["PermissionID"] = "25";Permissions[23]["PermissionClass"] = "administrator";Permissions[23]["Name"] = "A_MANAGEGROUPS";Permissions[23]["Founder"] = "0";Permissions[24] = [];Permissions[24]["PermissionID"] = "26";Permissions[24]["PermissionClass"] = "administrator";Permissions[24]["Name"] = "A_MANAGEFORUMS";Permissions[24]["Founder"] = "0";Permissions[25] = [];Permissions[25]["PermissionID"] = "27";Permissions[25]["PermissionClass"] = "administrator";Permissions[25]["Name"] = "A_MANAGEUSERS";Permissions[25]["Founder"] = "0";Permissions[26] = [];Permissions[26]["PermissionID"] = "28";Permissions[26]["PermissionClass"] = "administrator";Permissions[26]["Name"] = "A_MANAGESTYLES";Permissions[26]["Founder"] = "0";Permissions[27] = [];Permissions[27]["PermissionID"] = "29";Permissions[27]["PermissionClass"] = "administrator";Permissions[27]["Name"] = "A_MANAGEIMAGES";Permissions[27]["Founder"] = "0";Permissions[28] = [];Permissions[28]["PermissionID"] = "30";Permissions[28]["PermissionClass"] = "forum";Permissions[28]["Name"] = "F_POSTANN";Permissions[28]["Founder"] = "0";Permissions[29] = [];Permissions[29]["PermissionID"] = "31";Permissions[29]["PermissionClass"] = "forum";Permissions[29]["Name"] = "F_POSTBB";Permissions[29]["Founder"] = "0";Permissions[30] = [];Permissions[30]["PermissionID"] = "32";Permissions[30]["PermissionClass"] = "forum";Permissions[30]["Name"] = "F_DELETEOWN";Permissions[30]["Founder"] = "0";Permissions[31] = [];Permissions[31]["PermissionID"] = "33";Permissions[31]["PermissionClass"] = "forum";Permissions[31]["Name"] = "F_EDITOWN";Permissions[31]["Founder"] = "0";Permissions[32] = [];Permissions[32]["PermissionID"] = "34";Permissions[32]["PermissionClass"] = "forum";Permissions[32]["Name"] = "F_POSTIMAGES";Permissions[32]["Founder"] = "0";Permissions[33] = [];Permissions[33]["PermissionID"] = "35";Permissions[33]["PermissionClass"] = "forum";Permissions[33]["Name"] = "F_POSTLINKS";Permissions[33]["Founder"] = "0";Permissions[34] = [];Permissions[34]["PermissionID"] = "36";Permissions[34]["PermissionClass"] = "forum";Permissions[34]["Name"] = "F_STARTNEW";Permissions[34]["Founder"] = "0";Permissions[35] = [];Permissions[35]["PermissionID"] = "37";Permissions[35]["PermissionClass"] = "forum";Permissions[35]["Name"] = "F_NOAPPROVAL";Permissions[35]["Founder"] = "0";Permissions[36] = [];Permissions[36]["PermissionID"] = "38";Permissions[36]["PermissionClass"] = "forum";Permissions[36]["Name"] = "F_CANREPLY";Permissions[36]["Founder"] = "0";Permissions[37] = [];Permissions[37]["PermissionID"] = "39";Permissions[37]["PermissionClass"] = "forum";Permissions[37]["Name"] = "F_READFORUM";Permissions[37]["Founder"] = "0";Permissions[38] = [];Permissions[38]["PermissionID"] = "40";Permissions[38]["PermissionClass"] = "forum";Permissions[38]["Name"] = "F_USESIG";Permissions[38]["Founder"] = "0";Permissions[39] = [];Permissions[39]["PermissionID"] = "41";Permissions[39]["PermissionClass"] = "forum";Permissions[39]["Name"] = "F_LOCKOWN";Permissions[39]["Founder"] = "0";Permissions[40] = [];Permissions[40]["PermissionID"] = "42";Permissions[40]["PermissionClass"] = "forum";Permissions[40]["Name"] = "F_POSTSTICKY";Permissions[40]["Founder"] = "0";Permissions[41] = [];Permissions[41]["PermissionID"] = "43";Permissions[41]["PermissionClass"] = "forum";Permissions[41]["Name"] = "F_CANREPORT";Permissions[41]["Founder"] = "0";Permissions[42] = [];Permissions[42]["PermissionID"] = "44";Permissions[42]["PermissionClass"] = "forum";Permissions[42]["Name"] = "F_CANVIEW";Permissions[42]["Founder"] = "0";Permissions[43] = [];Permissions[43]["PermissionID"] = "45";Permissions[43]["PermissionClass"] = "forum";Permissions[43]["Name"] = "F_CANATTACH";Permissions[43]["Founder"] = "0";Permissions[44] = [];Permissions[44]["PermissionID"] = "46";Permissions[44]["PermissionClass"] = "forum";Permissions[44]["Name"] = "F_POSTHTML";Permissions[44]["Founder"] = "0";Permissions[45] = [];Permissions[45]["PermissionID"] = "47";Permissions[45]["PermissionClass"] = "forum";Permissions[45]["Name"] = "F_META";Permissions[45]["Founder"] = "0";   var GroupPermissions = [];GroupPermissions[0] = "21";GroupPermissions[1] = "22";GroupPermissions[2] = "23";GroupPermissions[3] = "24";GroupPermissions[4] = "25";GroupPermissions[5] = "26";GroupPermissions[6] = "27";GroupPermissions[7] = "28";GroupPermissions[8] = "29";  //~ document.write(Permissions[45]['Name'] + "<br />"); function ArrayFind(aArray,sString){	for (j in aArray) {		if (aArray[j] == sString){return true;}	}	return false;} var bg;var TableOpen = '<table border="1" cellpadding="2" cellspacing="2"><tbody>\n<tr><td>Permission</td><td>Yes</td><td>No</td></tr>\n';var TableClose = '</tbody><table>\n';Tables = []; for (i in Permissions) {	Tables[Permissions[i]['PermissionClass']]+='<tr><td>'+Permissions[i]['Name']+'</td><td><input id="'+i+'yes" name="'+Permissions[i]['Name']+'"type="radio"></td><td><input id="'+i+'no" name="'+Permissions[i]['Name']+'" type="radio"></td></tr>\n';	var hRadioYes = document.getElementById(i+'yes');	var hRadioNo = document.getElementById(i+'no');} for (key in Tables){	Tables[key] = TableOpen+Tables[key]+TableClose;	//~ document.write(key+":<br>"+Tables[key]+"\n");} for (i in Permissions) {	var hRadioYes = document.getElementById(i+'yes');	var hRadioNo = document.getElementById(i+'no');	if(ArrayFind(GroupPermissions,Permissions[i]['PermissionID'])){hRadioYes.checked = true;}else{hRadioNo.checked = true;}} //~ document.write(Tables['forum']);  </script> <div id="header"> <ul>  <li class="Selected" onclick="document.getElementById('content').innerHTML = Tables['user'];">{TAB1}</li>  <li class="NotSelected" onclick="document.getElementById('content').innerHTML = Tables['moderator'];">{TAB2}</li>  <li class="NotSelected" onclick="document.getElementById('content').innerHTML = Tables['administrator'];">{TAB3}</li>  <li class="NotSelected" onclick="document.getElementById('content').innerHTML = Tables['forum'];">{TAB4}</li></ul></div> <div id="content"></div>  </body></html> 

Thanks in advance.

Edited by SoItBegins
Link to comment
Share on other sites

Tables[key] starts with undefined. key can be any user, moderator, administrator or forum. for example: Tables['user'] starts with undefined.Tables[Permissions['PermissionClass']]+= .... ; appends string at the end of Tables[Permissions['PermissionClass']] and if key Permissions['PermissionClass'] does not exist in array it creates it automatically.I dont have any undefined variable. Really don't know how to fix.This is how I assemble/print html:

var TableOpen = '<table border="1" cellpadding="2" cellspacing="2"><tbody>\n<tr><td>Permission</td><td>Yes</td><td>No</td></tr>\n';var TableClose = '</tbody><table>\n';Tables = []; for (i in Permissions) {        Tables[Permissions[i]['PermissionClass']]+='<tr><td>'+Permissions[i]['Name']+'</td><td><input id="'+i+'yes" name="'+Permissions[i]['Name']+'"type="radio"></td><td><input id="'+i+'no" name="'+Permissions[i]['Name']+'" type="radio"></td></tr>\n';        var hRadioYes = document.getElementById(i+'yes');        var hRadioNo = document.getElementById(i+'no');} for (key in Tables){        Tables[key] = TableOpen+Tables[key]+TableClose;        //~ document.write(key+":<br>"+Tables[key]+"\n");}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...