Folks,
I have code that functions correctly, but I thought I would ask if any of you have ideas on how I can make the code more elegant so to speak.
Here is the scenario:
I have a grid that is dynamically built using the following code:
<script language="JavaScript">
var loopcounter;
document.write("<div id='Layer2' style='position:absolute; left:10px; top:120px; width:385px; height:355px; z-index:10'><table width='386' border='2' cellpadding='2' cellspacing='0' bordercolor='#000066' bgcolor='#EBEBEB'><tr class='textsmallbold' align='left'><td width='191' valign='middle'><div align='center'>Alert</div></td><td width='54' valign='middle'><div align='center'>Current Value</div></td><td width='68' valign='middle'><div align='center'>Change Value to...</div></td><td width='45' valign='middle'><div align='center'>More Info?</div></td></tr>");
for(loopcounter=0; loopcounter < window.parent.ID.length; loopcounter++)
{
document.write("<tr align='left'><td class='text_small' width='191' valign='middle'>");
//Statement writes description of option. Code is repeated for each option on this page
document.write(window.parent.ID[loopcounter][1]);
document.write("</td><td valign='middle' class='text_small'><div align='center'>");
//Statement writes what option is currently set to. Code is repeated for each option on this page
document.write(checkID[loopcounter][1]);
document.write("</div></td><td width='68' valign='middle'><div align='center'><select name='");
document.write(window.parent.ID[loopcounter][4]);
document.write("'id='");
document.write(window.parent.ID[loopcounter][4]);
document.write("'><option value='Y'>Yes<option value='N'>No</select></div></td><td width='45' valign='middle'><div align='center'>");
document.write("<a href='#'");
document.write(window.parent.ID[loopcounter][3]);
document.write(window.parent.ID[loopcounter][5]);
document.write("<img src='../../images/info_sm.gif' width='22' height='20' border='0'>");
document.write("</a></div></td></tr>");
}
document.write("<tr bgcolor='#000000' align='left'><td class='tinytext3' colspan='4' valign='middle'> </td></tr><tr align='center'><td class='text_small' colspan='4'><div align='center'><input type='submit'button name='set' id='btnSet' value='Submit' onClick=\x22window.parent.change();MM_goToURL('sel f','al_setup_res.htm');return document.MM_returnValue\x22><br><span class='note'>(Note: Click this button only when you have <br>finished making ALL of your selections.)</span> </div></td></tr></table>");
</script>
The following is an example of the array ot pulls info from:
ID[0] = new Array();
ID[0][0] = "3308";
ID[0][1] = "Allow ACTIVANT to receive your alerts as an email";
ID[0][2] = o3Web.sOptionGet(type,ID[0][0]);
ID[0][3] = "onMouseOver=\x22MM_setTextOfLayer('infoL','','%3C table width=%22197%22 height=%22216%22 border=%222%22 cellpadding=%225%22 cellspacing=%220%22 bordercolor=%22#CC0000%22 bgcolor=%22#000066%22%3E%0D%0A %3Ctr%3E %0D%0A %3Ctd valign=%22top%22 class=%22textsmallboldwhite%22%3EAllow ACTIVANT to receive alerts %0D%0A as an email%3C/td%3E%0D%0A %3C/tr%3E%0D%0A %3Ctr%3E %0D%0A %3Ctd valign=%22top%22 class=%22textsmallwhite%22%3EIf you have iNet, consider setting %0D%0A this option to %3Cb%3EYes%3C/b%3E so that Activant will receive notification via email %0D%0A when your system generates certain critical alerts, such as &quot;backup %0D%0A failed.&quot;%3Cbr%3E%0D%0A %3Cbr%3E%0D%0A Activant is currently developing an infrastructure to respond to these %0D%0A critical alerts. %0D%0A %3Cbr%3E%0D%0A%3C/td%3E%0D%0A %3C/tr%3E%0D%0A %3C/table%3E')\x22";
ID[0][4] = "opt3308";
ID[0][5] = "onMouseOut=\x22MM_setTextOfLayer('infoL','','')\x 22>";
The following is the change function tied to the submit button and this is where I think some streamlining with something like a for statement might be useful because this code repeats through the array...
function change()
{
bOptionSet(type,ID[0][0],window.content.frmAlert.opt3308.value);
switch (sOptionLastStatus())
{
case "OK":
break;
case "NS":
alert("You currently do not have the security to update system option " + ID[0][1] + ". To proceed, go to the Eagle Browser and sign on as a user with security to update Options Configuration.");
break;
case "NO":
alert("Unknown Error occurred while attempting to change " + ID[0][1] + ". Please make a note of what you were doing when this error occurred, and send it in an email to
[email protected].");
break;
default:
alert("Unknown Error occurred while attempting to change " + ID[0][1] + ". Please make a note of what you were doing when this error occurred, and send it in an email to
[email protected].");
break;
Sorry for the length but wanted to make sure you guys saw everything. Let me know your thoughts. Like I said, it works, but maybe it can be better.
Clay Hess