Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
DRM-free e-books 300x50
Closed Thread
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 23rd, 2004, 11:16 AM
Friend of Wrox
Join Date: Apr 2004
Location: Wausau, WI, USA.
Posts: 121
Thanks: 0
Thanked 0 Times in 0 Posts
Default Ideas to make code better


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("</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("</div></td><td width='68' valign='middle'><div align='center'><select name='");
    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("<img src='../../images/info_sm.gif' width='22' height='20' border='0'>");
document.write("<tr bgcolor='#000000' align='left'><td class='tinytext3' colspan='4' valign='middle'>&nbsp;</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>");

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 &amp;quot;backup %0D%0A failed.&amp;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()
        switch (sOptionLastStatus())
            case "OK":
            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.");
            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 tb@activant.com.");
                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 tb@activant.com.");

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
Clay Hess
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
make Exe out of VBA code roli2712 Excel VBA 2 July 4th, 2007 02:06 AM
Make IDE independent code getusama Java Basics 0 December 2nd, 2006 02:20 PM
make javascript code more dynamic crmpicco Javascript How-To 3 October 17th, 2005 05:40 AM
make javascript code more dynamic crmpicco Javascript How-To 1 September 27th, 2005 11:44 AM
Help..how to make confirmation code shopgirl Classic ASP Databases 1 March 3rd, 2004 02:09 PM

All times are GMT -4. The time now is 08:09 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.