Array issue

Discussion in 'JavaScript' started by Mosschops, Jun 19, 2007.

  1. #1
    I am sure this is quite basic but from an obscure angle.

    I am controlling a relay board using HTML and it reports the status of the relay using a range of replies. The page is served from the device using an extremely small and basic web server.

    To display this reply in the document served by the device (NETIOM) I only have to insert %61 for relay 1, %61 for relay 2 etc.

    I want to use this response to manipulate the page within IE by testing the state of relays and changing the background colour accordingly. However, I cannot seem to find a way to wedge this into my Javascript. Ideally I want the valuse to be held in an array to be tested later in the script. I did try the following and (obviously) it failed. If I can fix this issue I intend to roll this out to multiple identical devices performing very similar roles, hence using naming arrays which can quickly modify which device I am writing for.

    Any ideas about how to acheive this? I realise there are shortcomings with not using CSS etc but this is only for use by me and two other people internally on IE6/7, compatability outside this range is irrelevant.

    Oh, lastly this page is only one element of a larger framed web page.

    Any help would be appreciated.:)

    Thanks

    Mosschops

    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title></title>
    </head>
    <body>
    <TD><FORM METHOD=GET action="QX34OnOff_java_table.cgi">
    <B> Java Starts</B><BR>
    <HR>
    <SCRIPT LANGUAGE="Javascript">
    
    // This is the java I want to use
    
    // Set variables for this script - the % variables are a text value (On or Off) sent by the unit that serves the page (NETIOM).  
    // When I try and assign the values to the array I get a script error.  How do I do this?
    
    var relayDescriptionArray = new Array ("RLY1", "RLY2", "RLY3", "RLY4", "RLY5", "RLY6", "RLY7", "RLY8");
    var relayStateArray = new Array (%61, %62, %63, %64, %65, %66, %67, %68);
    
    // Start table
    
    document.write ("<TABLE>");
    
    // Display 1st row of table showing a button to activate each relay
    
    document.write ("<TR>");
    document.write ('<TD><INPUT TYPE=SUBMIT NAME=A01 VALUE="    Push    "></TD>' +
    		'<TD><INPUT TYPE=SUBMIT NAME=A02 VALUE="    Alarm    "></TD>' +
    		'<TD><INPUT TYPE=SUBMIT NAME=A03 VALUE="    Alarm    "></TD>' +
    		'<TD><INPUT TYPE=SUBMIT NAME=A04 VALUE="    Alarm    "></TD>' +
    		'<TD><INPUT TYPE=SUBMIT NAME=A05 VALUE="    Alarm    "></TD>' +
    		'<TD><INPUT TYPE=SUBMIT NAME=A06 VALUE="    Alarm    "></TD>' +
    		'<TD><INPUT TYPE=SUBMIT NAME=A07 VALUE="    Alarm    "></TD>' +
    		'<TD><INPUT TYPE=SUBMIT NAME=A08 VALUE="    Alarm    "></TD>');
    document.write ("</TR>");
    
    // Display 2nd row of data being the relay descriptions
    
    document.write ("<TR>");
    document.write ('<TD ALIGN="CENTER">' + relayDescriptionArray[0] + '</TD>' +
    		'<TD ALIGN="CENTER">' + relayDescriptionArray[1] + '</TD>' +
    		'<TD ALIGN="CENTER">' + relayDescriptionArray[2] + '</TD>' +
    		'<TD ALIGN="CENTER">' + relayDescriptionArray[3] + '</TD>' +
    		'<TD ALIGN="CENTER">' + relayDescriptionArray[4] + '</TD>' +
    		'<TD ALIGN="CENTER">' + relayDescriptionArray[5] + '</TD>' +
    		'<TD ALIGN="CENTER">' + relayDescriptionArray[6] + '</TD>' +
    		'<TD ALIGN="CENTER">' + relayDescriptionArray[7] + '</TD>');
    document.write ("</TR>");
    
    //Display 3rd row of data being the relay states
    
    document.write ("<TR>");
    document.write ('<TD ALIGN="CENTER">' + relayStateArray[0] + '</TD>' +
    		'<TD ALIGN="CENTER">' + relayStateArray[1] + '</TD>' +
    		'<TD ALIGN="CENTER">' + relayStateArray[2] + '</TD>' +
    		'<TD ALIGN="CENTER">' + relayStateArray[3] + '</TD>' +
    		'<TD ALIGN="CENTER">' + relayStateArray[4] + '</TD>' +
    		'<TD ALIGN="CENTER">' + relayStateArray[5] + '</TD>' +
    		'<TD ALIGN="CENTER">' + relayStateArray[6] + '</TD>' +
    		'<TD ALIGN="CENTER">' + relayStateArray[7] + '</TD>');
    document.write ("</TR>");
    
    
    // Display 4th row of table showing button to deactivate each relay
    
    document.write ("<TR>");
    document.write ('<TD><INPUT TYPE=SUBMIT NAME=A01 VALUE="Release"></TD>' +
    		'<TD><INPUT TYPE=SUBMIT NAME=A02 VALUE="    Clear     "></TD>' +
    		'<TD><INPUT TYPE=SUBMIT NAME=A03 VALUE="    Clear     "></TD>' +
    		'<TD><INPUT TYPE=SUBMIT NAME=A04 VALUE="    Clear     "></TD>' +
    		'<TD><INPUT TYPE=SUBMIT NAME=A05 VALUE="    Clear     "></TD>' +
    		'<TD><INPUT TYPE=SUBMIT NAME=A06 VALUE="    Clear     "></TD>' +
    		'<TD><INPUT TYPE=SUBMIT NAME=A07 VALUE="    Clear     "></TD>' +
    		'<TD><INPUT TYPE=SUBMIT NAME=A08 VALUE="    Clear     "></TD>');
    document.write ("</TR>");
    
    // Close table
    
    document.write ("</TABLE>");
    
    // The html which follows below displays the values correctly
    
    
    </SCRIPT>
    <HR>
    <!-- This HTML displays the values given by the NETIOM correctly when served from the device -->
    <B>Standard HTML</B><BR><BR>
    <TABLE WIDTH=150 BORDER=1>
    <tr>
    <TD ALIGN="CENTER"> Relay1 </TD>
    <TD ALIGN="CENTER"> Relay2 </TD>
    <TD ALIGN="CENTER"> Relay3 </TD>
    <TD ALIGN="CENTER"> Relay4 </TD>
    <TD ALIGN="CENTER"> Relay5 </TD>
    <TD ALIGN="CENTER"> Relay6 </TD>
    <TD ALIGN="CENTER"> Relay7 </TD>
    <TD ALIGN="CENTER"> Relay8 </TD>
    </TR>
    <TR>
    <TD ALIGN="CENTER"> %61 </TD>
    <TD ALIGN="CENTER"> %62 </TD>
    <TD ALIGN="CENTER"> %63 </TD>
    <TD ALIGN="CENTER"> %64 </TD>
    <TD ALIGN="CENTER"> %65 </TD>
    <TD ALIGN="CENTER"> %66 </TD>
    <TD ALIGN="CENTER"> %67 </TD>
    <TD ALIGN="CENTER"> %68 </TD>
    </TR>
    </TABLE>
    
    
    </BODY>
    </HTML>
    
    
    Code (markup):
     
    Mosschops, Jun 19, 2007 IP
  2. DavidMerrilees

    DavidMerrilees Guest

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Put your array values in quotes.
     
    DavidMerrilees, Jun 20, 2007 IP
  3. Mosschops

    Mosschops Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Cheers David, will give it a go.
     
    Mosschops, Jun 20, 2007 IP