SitePoint Sponsor

User Tag List

Results 1 to 15 of 15
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2010
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Post oDay is undefined

    Hello guys,

    I have this javascript undefined:

    function:

    PHP Code:
    function printInternationalDate(dateoDayoMonthoYear)
    {
        
    oDay.value date.getDate();
        
    oMonth.value fixMonth(date.getMonth());
        
    oYear.value date.getFullYear();



    HTML:
    PHP Code:
                            <select name="fromDateDay" id="fromDateDay">
                                <
    option value="">- Day -</option>
    <%        for 
    1 to 31 %>
                                <
    option value="<%= x %>" <% if fromDateDay x then response.write("selected") %> ><%= %></option>
    <%        
    next %>
                            </
    select


    calling function:
    PHP Code:
    <class="SmallLinks" href="javascript:InternationalDateRange('Week to Date', document.forms[0].fromDateDay, document.forms[0].fromDateMonth, document.forms[0].fromDateYear, document.forms[0].toDateDay, document.forms[0].toDateMonth, document.forms[0].toDateYear)">Week to Date</a



    generated HTML:

    PHP Code:
                            <select name="fromDateDay" id="fromDateDay">
                                <
    option value="">- Day -</option>

                                <
    option value="1" selected >1</option>

                                <
    option value="2"  >2</option>

                                <
    option value="3"  >3</option>

                                <
    option value="4"  >4</option>

                                <
    option value="5"  >5</option>

                                <
    option value="6"  >6</option>

                                <
    option value="7"  >7</option>

                                <
    option value="8"  >8</option>

                                <
    option value="9"  >9</option>

                                <
    option value="10"  >10</option>

                                <
    option value="11"  >11</option>

                                <
    option value="12"  >12</option>

                                <
    option value="13"  >13</option>

                                <
    option value="14"  >14</option>

                                <
    option value="15"  >15</option>

                                <
    option value="16"  >16</option>

                                <
    option value="17"  >17</option>

                                <
    option value="18"  >18</option>

                                <
    option value="19"  >19</option>

                                <
    option value="20"  >20</option>

                                <
    option value="21"  >21</option>

                                <
    option value="22"  >22</option>

                                <
    option value="23"  >23</option>

                                <
    option value="24"  >24</option>

                                <
    option value="25"  >25</option>

                                <
    option value="26"  >26</option>

                                <
    option value="27"  >27</option>

                                <
    option value="28"  >28</option>

                                <
    option value="29"  >29</option>

                                <
    option value="30"  >30</option>

                                <
    option value="31"  >31</option>

                            </
    select

  2. #2
    SitePoint Enthusiast
    Join Date
    Feb 2010
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Error is:

    oDay is undefined... I am not sure why it is....

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2010
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    that error occurs when I click the link "Week to Date"

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    The link calls the InternationalDateRange() function which you haven't shown. Is the printInternationalDate() function called from there?

    It will be easiest to come to a quick solution if we had a web page that we could experience this on.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    SitePoint Enthusiast
    Join Date
    Feb 2010
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by pmw57 View Post
    The link calls the InternationalDateRange() function which you haven't shown. Is the printInternationalDate() function called from there?

    It will be easiest to come to a quick solution if we had a web page that we could experience this on.

    Hello,

    The printInternationalDate() function is shown on the above thread. Here is the generated HTML, please see attachment.

    Thanks in advance.
    Attached Files Attached Files

  6. #6
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by neo_phyte View Post
    Hello,

    The printInternationalDate() function is shown on the above thread.
    The problem occurs with oDay that is passed to the printInternationalDate() function, so what needs to be found is the code that calls that function.

    Quote Originally Posted by neo_phyte View Post
    Here is the generated HTML, please see attachment.
    Okay, it's still awaiting approval at this stage.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  7. #7
    SitePoint Enthusiast
    Join Date
    Feb 2010
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by pmw57 View Post
    The problem occurs with oDay that is passed to the printInternationalDate() function, so what needs to be found is the code that calls that function.



    Okay, it's still awaiting approval at this stage.

    Code:
    <a class="SmallLinks" href="javascript:InternationalDateRange('Week to Date', document.forms[0].fromDateDay, document.forms[0].fromDateMonth, document.forms[0].fromDateYear, document.forms[0].toDateDay, document.forms[0].toDateMonth, document.forms[0].toDateYear)">Week to Date</a>
    That's it..

  8. #8
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by neo_phyte View Post
    Code:
    <a class="SmallLinks" href="javascript:InternationalDateRange('Week to Date', document.forms[0].fromDateDay, document.forms[0].fromDateMonth, document.forms[0].fromDateYear, document.forms[0].toDateDay, document.forms[0].toDateMonth, document.forms[0].toDateYear)">Week to Date</a>
    That's it..
    I don't see printInternationalDate in that lot. What I do see there is InternationalDateRange
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  9. #9
    SitePoint Enthusiast
    Join Date
    Feb 2010
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by pmw57 View Post
    I don't see printInternationalDate in that lot. What I do see there is InternationalDateRange

    Here it is:

    That HTML is is calling InternationalDateRange function, and that function is calling printInternationalDate function.

    Code:
    function InternationalDateRange(sRange, oFromDate_day, oFromDate_month, oFromDate_year, oToDate_day, oToDate_month, oToDate_year)
    {
    	//the current date
    	date = new Date();
    	//1000 seconds in a millisecond, 60 seconds in a minute, etc...
    	var day = 1000 * 60 * 60 * 24;
    	
    	//loop through acceptable date ranges
    	switch (sRange)
    	{
    		case "Week to Date":
    			/* To: Today */ printInternationalDate(date, oToDate_day, oToDate_month, oToDate_year);
    			
    			//subrtact day of the week number of days from today
    			date.setTime( date.getTime() - fixDay(date.getDay()) * day );
    			/* From: First Day of the Week */ printInternationalDate(date, oFromDate_day, oFromDate_month, oFromDate_year);
    			break;
    
    	}
    }

  10. #10
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Okay, so oToDate_day is giving the undefined value, which comes from the 5th parameter that is passed to InternationalDateRange

    Now we know where the undefined value is coming from, it's coming from document.forms[0].toDateDay

    Where is toDateDay?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  11. #11
    SitePoint Enthusiast
    Join Date
    Feb 2010
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by pmw57 View Post
    Okay, so oToDate_day is giving the undefined value, which comes from the 5th parameter that is passed to InternationalDateRange

    Now we know where the undefined value is coming from, it's coming from document.forms[0].toDateDay

    Where is toDateDay?

    Code:
    						<select name="toDateDay" id="toDateDay">
    							<option value="">- Day -</option>
    <%		for x = 1 to 31 %>
    							<option value="<%= x %>" <% if toDateDay = x then response.write("selected") %> ><%= x %></option>
    <%		next %>
    						</select>

  12. #12
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    That's great, so we've come to the end of basic troubleshooting.

    Next up is to experience the script and the generated html together within the web browser, so that finer details can be discovered.

    Do you happen to have something as a web page somewhere so that the problem can be experienced, so that a solution can be found for you?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  13. #13
    SitePoint Enthusiast
    Join Date
    Feb 2010
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No, I have only a copy in my localhost.

  14. #14
    SitePoint Enthusiast
    Join Date
    Feb 2010
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually this works before in IE and Firefox, but when I changed this DTD from transitional to strict, it does not work now in IE and Firefox.

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

    to

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

    So, I am thinking the issue here is the some elements don't work in strict. Maybe the elements are not compatible with strict DTD.

  15. #15
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    This extra information means that it' strongly likely to be a structural problem with the HTML code itself.

    In cases like this, fixing HTML problems within the code has a high chance of success towards fixing the problem.

    Run the HTML code through http://validator.w3.org/ and see how the script performs once the HTML code passes validation.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •