Error on Page

Discussion in 'JavaScript' started by santanu, Oct 23, 2008.

  1. #1
    when I run this page on the browser on the bottom left corner I am getting "Error on page" with warning yellow triangle sign. If I click on this triangle sign the information below shows in a pop up window.

    Line: 726
    Char: 4
    Error: 'length' is null or not an object
    Code: 0
    URL: http://....../WardenConfig/deviceNoiceAnalysis.jsp

    I did some experiment on this issue and I found when we remove this <body onLoad="setDefaultNoiseTime();"> form the JSP the error does not exist. So I beleive this javascript error is generating in the function "setDefaultNoiseTime()". But I could not figure out what is the problem in this function. The function is below:

    function setDefaultNoiseTime()
    {
    // Find the current date and hour
    // Set the start date and time to the current date and hour
    // Set the end date and time to the current date and hour

    var now = new Date();
    var currentYear = "" + now.getYear();
    var currentMonth = "" + (now.getMonth() + 1); // 1-12

    // if( currentMonth.length == 1 )
    // {
    // currentMonth = "0" + currentMonth;
    // }

    var currentMonthName = getMonthName( currentMonth );

    var currentDay = "" + now.getDate();
    if( currentDay.length == 1 )
    {
    currentDay = "0" + currentDay;
    }
    var currentHour = "" + now.getHours(); // 0-23
    if( currentHour.length == 1 )
    {
    currentHour = "0" + currentHour;
    }

    // Now select the appropriate index in each dropdown :
    setSelection( document.formSettings.selectStartYear, currentYear );
    setSelection( document.formSettings.selectStartMonth, currentMonthName );
    setSelection( document.formSettings.selectStartDay, currentDay );
    setSelection( document.formSettings.selectStartHour, currentHour );

    setSelection( document.formSettings.selectEndYear, currentYear );
    setSelection( document.formSettings.selectEndMonth, currentMonthName );
    setSelection( document.formSettings.selectEndDay, currentDay );
    setSelection( document.formSettings.selectEndHour, currentHour );
    }

    Please help me to resolve this issue. Thanks....
     
    santanu, Oct 23, 2008 IP
  2. lp1051

    lp1051 Well-Known Member

    Messages:
    163
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    108
    #2
    Hi, it's a little bit unusual to cast numbers into string when you don't have to, but I'll try to follow your code.
    Where is your function - getMonthName()?? Because here on this example there's no reason for the error. Can you post code of that function as well? And maybe also function setSelection()...
     
    lp1051, Oct 23, 2008 IP
  3. santanu

    santanu Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    here is the markup language:

    <body onLoad="setDefaultNoiseTime();">
    <form name="formSettings" method="post" action="./servlet/WardenConfigController" target="_blank">
    <input type="hidden" name="wardenAction" value="">

    <table class="main" border="0" cellspacing="0" cellpadding="0">
    <jsp:include page="begin.jsp">
    <jsp:param name="title" value="<%=TITLE%>"/>
    </jsp:include>

    <!-- a row with the body of the page -->
    <tr>
    <td>
    <table height="100%" width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <!-- the navigation column : hard-coded width of 160 pixels -->

    <td class="nav-column">
    <br>
    <%=ConfigNavigator.getInstance().HtmlNavigation( "noise-analysis" )%>
    </td>

    <%
    if( theDevices != null )
    {
    %>
    <td class="main-column"> <!-- the main content column -->
    <table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#EFEFEF">

    <tr>
    <td align="center">&nbsp; </td>
    </tr>

    <tr>
    <td align="center">
    <table width="88%" height="23" border="0" cellpadding="0" cellspacing="0">
    <tr>
    <td class="input-style-3">&nbsp;</td>
    <td class="input-style-3">YYYY</td>
    <td class="input-style-3">MM</td>
    <td class="input-style-3">DD</td>
    <td class="input-style-3">HH</td>
    <td width="11%" class="input-style-3">MM</td>
    <td width="8%" class="input-style-3">&nbsp;</td>
    </tr>
    <tr>
    <td class="input-style-3"><div align="left">Start Date/Time : </div></td>
    <td width="13%" class="input-style-3">
    <div align="center">
    <select name="selectStartYear" size="1" id="selectStartYear">
    <option value="2007">2007</option>
    <option value="2008">2008</option>
    <option value="2009">2009</option>
    <option value="2010">2010</option>
    <option value="2011">2011</option>

    </select>
    </div></td>
    <td width="12%" class="input-style-3">
    <div align="center">
    <select name="selectStartMonth" size="1" id="selectStartMonth">
    <option>Jan</option>
    <option>Feb</option>
    <option>Mar</option>
    <option>Apr</option>
    <option>May</option>
    <option>Jun</option>
    <option>Jul</option>
    <option>Aug</option>
    <option>Sep</option>
    <option>Oct</option>
    <option>Nov</option>
    <option>Dec</option>
    </select>
    </div></td>
    <td width="11%" class="input-style-3">
    <div align="center">
    <select name="selectStartDay" size="1" id="selectStartDay">
    <option>01</option>
    <option>02</option>
    <option>03</option>
    <option>04</option>
    <option>05</option>
    <option>06</option>
    <option>07</option>
    <option>08</option>
    <option>09</option>
    <option>10</option>
    <option>11</option>
    <option>12</option>
    <option>13</option>
    <option>14</option>
    <option>15</option>
    <option>16</option>
    <option>17</option>
    <option>18</option>
    <option>19</option>
    <option>20</option>
    <option>21</option>
    <option>22</option>
    <option>23</option>
    <option>24</option>
    <option>25</option>
    <option>26</option>
    <option>27</option>
    <option>28</option>
    <option>29</option>
    <option>30</option>
    <option>31</option>
    </select>
    </div></td>
    <td width="13%" class="input-style-3">
    <div align="center">
    <select name="selectStartHour" size="1" id="selectStartHour">
    <option>00</option>
    <option>01</option>
    <option>02</option>
    <option>03</option>
    <option>04</option>
    <option>05</option>
    <option>06</option>
    <option>07</option>
    <option>08</option>
    <option>09</option>
    <option>10</option>
    <option>11</option>
    <option>12</option>
    <option>13</option>
    <option>14</option>
    <option>15</option>
    <option>16</option>
    <option>17</option>
    <option>18</option>
    <option>19</option>
    <option>20</option>
    <option>21</option>
    <option>22</option>
    <option>23</option>
    </select>
    </div></td>
    <td colspan="2" class="input-style-3">
    <div align="left">
    <select name="selectStartMinute" size="1" id="selectStartMinute">
    <option>00</option>
    <option>01</option>
    <option>02</option>
    <option>03</option>
    <option>04</option>
    <option>05</option>
    <option>06</option>
    <option>07</option>
    <option>08</option>
    <option>09</option>
    <option>10</option>
    <option>11</option>
    <option>12</option>
    <option>13</option>
    <option>14</option>
    <option>15</option>
    <option>16</option>
    <option>17</option>
    <option>18</option>
    <option>19</option>
    <option>20</option>
    <option>21</option>
    <option>22</option>
    <option>23</option>
    <option>24</option>
    <option>25</option>
    <option>26</option>
    <option>27</option>
    <option>28</option>
    <option>29</option>
    <option>30</option>
    <option>31</option>
    <option>32</option>
    <option>33</option>
    <option>34</option>
    <option>35</option>
    <option>36</option>
    <option>37</option>
    <option>38</option>
    <option>39</option>
    <option>40</option>
    <option>41</option>
    <option>42</option>
    <option>43</option>
    <option>44</option>
    <option>45</option>
    <option>46</option>
    <option>47</option>
    <option>48</option>
    <option>49</option>
    <option>50</option>
    <option>51</option>
    <option>52</option>
    <option>53</option>
    <option>54</option>
    <option>55</option>
    <option>56</option>
    <option>57</option>
    <option>58</option>
    <option>59</option>
    </select>
    </div></td>
    </tr>
    <tr>
    <td width="32%" class="input-style-3"><div align="left">End Date/Time : </div></td>
    <td width="13%" class="input-style-3">
    <div align="center">
    <select name="selectEndYear" size="1" id="selectEndYear">
    <option value="2007">2007</option>
    <option value="2008">2008</option>
    <option value="2009">2009</option>
    <option value="2010">2010</option>
    <option value="2011">2011</option>
    <option value="2012">2012</option>
    <option value="2013">2013</option>
    <option value="2014">2014</option>
    <option value="2015">2015</option>
    <option value="2016">2016</option>
    <option value="2017">2017</option>
    <option value="2018">2018</option>
    <option value="2019">2019</option>
    <option value="2020">2020</option>
    </select>
    </div></td>
    <td width="12%" class="input-style-3">
    <div align="center">
    <select name="selectEndMonth" size="1" id="selectEndMonth">
    <option>Jan</option>
    <option>Feb</option>
    <option>Mar</option>
    <option>Apr</option>
    <option>May</option>
    <option>Jun</option>
    <option>Jul</option>
    <option>Aug</option>
    <option>Sep</option>
    <option>Oct</option>
    <option>Nov</option>
    <option>Dec</option>
    </select>
    </div></td>
    <td width="11%" class="input-style-3">
    <div align="center">
    <select name="selectEndDay" size="1" id="selectEndDay">
    <option>01</option>
    <option>02</option>
    <option>03</option>
    <option>04</option>
    <option>05</option>
    <option>06</option>
    <option>07</option>
    <option>08</option>
    <option>09</option>
    <option>10</option>
    <option>11</option>
    <option>12</option>
    <option>13</option>
    <option>14</option>
    <option>15</option>
    <option>16</option>
    <option>17</option>
    <option>18</option>
    <option>19</option>
    <option>20</option>
    <option>21</option>
    <option>22</option>
    <option>23</option>
    <option>24</option>
    <option>25</option>
    <option>26</option>
    <option>27</option>
    <option>28</option>
    <option>29</option>
    <option>30</option>
    <option>31</option>
    </select>
    </div></td>
    <td width="13%" class="input-style-3">
    <div align="center">
    <select name="selectEndHour" size="1" id="selectEndHour">
    <option>00</option>
    <option>01</option>
    <option>02</option>
    <option>03</option>
    <option>04</option>
    <option>05</option>
    <option>06</option>
    <option>07</option>
    <option>08</option>
    <option>09</option>
    <option>10</option>
    <option>11</option>
    <option>12</option>
    <option>13</option>
    <option>14</option>
    <option>15</option>
    <option>16</option>
    <option>17</option>
    <option>18</option>
    <option>19</option>
    <option>20</option>
    <option>21</option>
    <option>22</option>
    <option>23</option>
    </select>
    </div></td>
    <td colspan="2" class="input-style-3">
    <div align="left">
    <select name="selectEndMinute" size="1" id="selectEndMinute">
    <option>00</option>
    <option>01</option>
    <option>02</option>
    <option>03</option>
    <option>04</option>
    <option>05</option>
    <option>06</option>
    <option>07</option>
    <option>08</option>
    <option>09</option>
    <option>10</option>
    <option>11</option>
    <option>12</option>
    <option>13</option>
    <option>14</option>
    <option>15</option>
    <option>16</option>
    <option>17</option>
    <option>18</option>
    <option>19</option>
    <option>20</option>
    <option>21</option>
    <option>22</option>
    <option>23</option>
    <option>24</option>
    <option>25</option>
    <option>26</option>
    <option>27</option>
    <option>28</option>
    <option>29</option>
    <option>30</option>
    <option>31</option>
    <option>32</option>
    <option>33</option>
    <option>34</option>
    <option>35</option>
    <option>36</option>
    <option>37</option>
    <option>38</option>
    <option>39</option>
    <option>40</option>
    <option>41</option>
    <option>42</option>
    <option>43</option>
    <option>44</option>
    <option>45</option>
    <option>46</option>
    <option>47</option>
    <option>48</option>
    <option>49</option>
    <option>50</option>
    <option>51</option>
    <option>52</option>
    <option>53</option>
    <option>54</option>
    <option>55</option>
    <option>56</option>
    <option>57</option>
    <option>58</option>
    <option>59</option>
    </select>
    </div></td>
    </tr>
    </table>
    </td>
    </tr>

    <tr>
    <td>
    <hr>
    </td>
    </tr>

    <tr>
    <td align="center">
    <div align="left"></div>
    <div align="left"></div>
    <table width="88%" height="23" border="0" cellpadding="0" cellspacing="0">
    <tr>
    <td width="47%" class="input-style-3"><div align="left">Device Name</div></td>
    <td width="31%" class="input-style-3"><div align="left">Type</div></td>
    <td width="22%" class="input-style-3"><div align="left">&nbsp;Noise</div></td>
    </tr>
    </table>
    </td>
    </tr>

    <tr>
    <td align="center">
    <div class="scrolldevicenoise">
    &nbsp;<table id="tagTable" width="100%" border="0" cellspacing="0" cellpadding="1">
    <%
    int rowCount = 0;
    String backColor = "";
    if( theDevices != null )
    {
    for( int x = 0; x < theDevices.length; x++ )
    {
    String guid = theDevices[x].getGUID();
    String name = theDevices[x].getName();
    String type = theDevices[x].getType();
    String noiseGUIDFieldName = "noiseGUID" + x;
    String noiseShowFieldName = "showNoise" + x;

    if( (rowCount % 2 == 0 ) )
    {
    backColor = "#FFFFFF";
    }
    else
    {
    backColor = "#CCCCCC";
    }
    %>
    <tr bgcolor="<%=backColor%>">
    <td width="47%" class="input-style-4">
    <div align="left"><%=name%></div></td>
    <td width="32%" class="input-style-4">
    <div align="left"><%=type%></div></td>
    <td bgcolor="#CCCCCC" width="21%" class="input-style-4">
    <div align="left">
    <input name="<%=noiseGUIDFieldName%>" type="hidden" value="<%=guid%>">
    <input type="checkbox" name="<%=noiseShowFieldName%>" value="true" onClick="updateCount(this);">
    </div></td>
    </tr>
    <%
    rowCount++;
    }
    }
    %>
    </table>
    </div> </td>
    </tr>
    <!-- ends row for data entry -->

    <tr>
    <td>
    <hr>
    </td>
    </tr>

    <!-- Row for buttons -->
    <tr>
    <td align="center">
    <table width="50%" border="0" cellspacing="2" cellpadding="5">
    <tr>
    <td width="25%">
    <div align="center">
    <input name="btnNoise" type="button" id="btnNoise" onClick="handleShowNoise();" value="Show Noise" />
    </div>
    </td>
    <!--td width="25%">
    <div align="center">
    <input name="btnClose" type="button" id="btnClose" onClick="handleClose();" value="Close" />
    </div>
    </td-->
    </tr>
    </table>
    </td>
    </tr>
    <!-- ends row for buttons -->

    </table>
    </td> <!-- This ends "the main content column" -->

    <%
    } // end if( devices != null )
    else
    {
    %>
    <td width="311" class="main-column"> <!-- the NULL DEVICE content column -->
    <table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#EFEFEF">
    <tr>
    <td align="center">
    <table width="90%" border="1" cellspacing="0" cellpadding="1">
    <tr>
    <td class="input-style-3"><div align="center">COULD NOT UPDATE NOISE DATA </div></td>
    </tr>
    </table>
    </td>
    </tr>
    <tr>
    <td align="center">
    <table width="90%" border="1" cellspacing="0" cellpadding="1">
    <tr>
    <td width="50%">
    <div align="center"> </div>
    </td>
    </tr>
    </table>
    </td>
    </tr>
    </table>
    </td> <!-- This ends "the NULL DEVICE content column" -->
    <%
    }
    %>
    </tr> </table> </td>
    </tr>
    </table>
    </form>
    </body>
     
    santanu, Oct 24, 2008 IP
  4. santanu

    santanu Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Here is the javascript functions:

    <script language="JavaScript" src="js/rftJSLib.js"></script>
    <script language="JavaScript">
    var totalCount = 0;
    var maxCount = 4;
    function updateCount( field )
    {
    if( field.checked )
    {
    totalCount++;
    }
    else
    {
    totalCount--;
    }

    // alert( "totalCount was now " + totalCount );
    }

    function handleShowNoise()
    {
    if( validate() )
    {
    // disable( document.formSettings.btnNoise );
    document.formSettings.wardenAction.value = "get.device.noise";
    document.formSettings.submit();
    }
    }

    function validate()
    {
    if( totalCount > maxCount )
    {
    alert( "A maximum of " + maxCount + " devices may be selected." );
    return false;
    }
    else if( totalCount < 1 )
    {
    alert( "Please select a device." );
    return false;
    }
    else
    {
    return true;
    }
    }

    function handleClose()
    {
    document.formSettings.wardenAction.value="launch.configuration";
    document.formSettings.submit();
    }

    function setDefaultNoiseTime()
    {
    // Find the current date and hour
    // Set the start date and time to the current date and hour
    // Set the end date and time to the current date and hour

    var now = new Date();
    var currentYear = "" + now.getYear();
    var currentMonth = "" + (now.getMonth() + 1); // 1-12

    // if( currentMonth.length == 1 )
    // {
    // currentMonth = "0" + currentMonth;
    // }

    var currentMonthName = getMonthName( currentMonth );

    var currentDay = "" + now.getDate();
    if( currentDay.length == 1 )
    {
    currentDay = "0" + currentDay;
    }
    var currentHour = "" + now.getHours(); // 0-23
    if( currentHour.length == 1 )
    {
    currentHour = "0" + currentHour;
    }

    // Now select the appropriate index in each dropdown :
    setSelection( document.formSettings.selectStartYear, currentYear );
    setSelection( document.formSettings.selectStartMonth, currentMonthName );
    setSelection( document.formSettings.selectStartDay, currentDay );
    setSelection( document.formSettings.selectStartHour, currentHour );

    setSelection( document.formSettings.selectEndYear, currentYear );
    setSelection( document.formSettings.selectEndMonth, currentMonthName );
    setSelection( document.formSettings.selectEndDay, currentDay );
    setSelection( document.formSettings.selectEndHour, currentHour );
    }
    </script>
     
    santanu, Oct 24, 2008 IP
  5. lp1051

    lp1051 Well-Known Member

    Messages:
    163
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    108
    #5
    Hi, not bad... But still the two functions I've asked for are missing... Try to search for 'function getMonthName(' and 'function setSelection(' somewhere in the files. It could be maybe even here - js/rftJSLib.js.
     
    lp1051, Oct 25, 2008 IP
  6. santanu

    santanu Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I am sorry...
    Here is the function:

    function getMonthName( monthNumber, bFullName )
    {
    var monthShortNames = new Array(12);
    var monthFullNames = new Array(12);

    monthShortNames[1] = "Jan";
    monthShortNames[2] = "Feb";
    monthShortNames[3] = "Mar";
    monthShortNames[4] = "Apr";
    monthShortNames[5] = "May";
    monthShortNames[6] = "Jun";
    monthShortNames[7] = "Jul";
    monthShortNames[8] = "Aug";
    monthShortNames[9] = "Sep";
    monthShortNames[10] = "Oct";
    monthShortNames[11] = "Nov";
    monthShortNames[12] = "Dec";

    monthFullNames[1] = "January";
    monthFullNames[2] = "February";
    monthFullNames[3] = "March";
    monthFullNames[4] = "April";
    monthFullNames[5] = "May";
    monthFullNames[6] = "June";
    monthFullNames[7] = "July";
    monthFullNames[8] = "August";
    monthFullNames[9] = "September";
    monthFullNames[10] = "October";
    monthFullNames[11] = "November";
    monthFullNames[12] = "December";

    if( bFullName == "true" )
    {
    return monthFullNames[ monthNumber ];
    }
    else
    {
    return monthShortNames[ monthNumber ];
    }
    }
     
    santanu, Oct 27, 2008 IP
  7. santanu

    santanu Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Here is another function:

    function setSelection( listVar, value )
    {
    var listLength = listVar.length;
    // alert( 'listLength is ' + listLength );
    // alert( 'listVar[0].text is ' + listVar.options[0].text );
    // alert( 'value is ' + value );

    for (i = 0; i < listLength; i++)
    {
    if (listVar.options.text == value )
    {
    selectOption( listVar, i );
    break;
    }
    }

    return true;
    }
     
    santanu, Oct 27, 2008 IP
  8. lp1051

    lp1051 Well-Known Member

    Messages:
    163
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    108
    #8
    Hi, yes, that's it, thanks. But I have very strange conclusion. I tried to use the code without ASP, JSP just pure HTML and Javascript and everything works great. IE6+, FF2+, both fine.
    So I have more guessing than answer.
    *First was another function selectOption - that I rewrote as : listVar.options.selected = true; But I believe you have the same form of this function.
    *Then based on the error message from IE, which is really bad for debugging (try to install FF if you need to get some meaningfull response from browser about errors), the only other place connected with length property is :
    if( theDevices != null ) {
    for( int x = 0; x < theDevices.length; x++ )

    This, I have no chance to verify or check, but the condition !=null could pass even number (e.g. 0) which has no length. Do you think it could be there?

    Anyway, your function setDefaultNoiseTime() works fine, without error, called on body onload, using the code provided (cleaned from JSP, ASP). Hope it helps you in some way...
     
    lp1051, Oct 28, 2008 IP