Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Feb 2011
    Posts
    23
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Why is this function not working in Internet Explorer?

    I have the following Javascript function that just refuses to work in Internet Explorer (since IE is absolute .......). Can anybody tell me why this wouldn't be working in IE and what I need to do to fix it? I am new to Javascript so don't really have any idea

    Code:
    function displaymember()
    
    {
    
        var d = new Date();
    
        var curr_date = d.getDate();
    
        if (curr_date < 10)
    
        curr_date = "0" + curr_date;
    
        var curr_month = d.getMonth();
    
        curr_month++;
    
        if (curr_month < 10)
    
        curr_month = "0" + curr_month;
    
        var curr_year = d.getFullYear();
    
        //alert("date="+curr_date+" month="+curr_month+" year="+curr_year);
        for (i = 0; i < x.length; i++)
    
        {
    
            membershipstatus = (x[i].getElementsByTagName("membership_status")[0].childNodes[0].nodeValue);
    
            name = (x[i].getElementsByTagName("name")[0].childNodes[0].nodeValue);
    
            body = (x[i].getElementsByTagName("body_type")[0].childNodes[0].nodeValue);
    
            ethnicity = (x[i].getElementsByTagName("ethnicity")[0].childNodes[0].nodeValue);
    
            sex = (x[i].getElementsByTagName("sex")[0].childNodes[0].nodeValue);
    
            profession = (x[i].getElementsByTagName("profession")[0].childNodes[0].nodeValue);
    
            seeking = (x[i].getElementsByTagName("seeking")[0].childNodes[0].nodeValue);
    
            date = (x[i].getElementsByTagName("date_joined")[0]);
    
            month = (date.getElementsByTagName("month")[0].childNodes[0].nodeValue);
    
            year = (date.getElementsByTagName("year")[0].childNodes[0].nodeValue);
    
            newa = document.createElement('a');
    
            aIdName = 'my' + i + 'a';
    
            ahref = '#';
    
            aclick = 'show(' + i + ')';
    
            newa.setAttribute('id', aIdName);
    
            newa.setAttribute('href', ahref);
    
            newa.setAttribute('onclick', aclick);
    
            newa.innerHTML = name + " | " + body + " " + ethnicity + " " + sex + " " + profession + " with " + membershipstatus + " membership seeks " + seeking + "<br/>";
    
            if (curr_month == month && curr_year == year) {
    
                document.getElementById("member").appendChild(newa);
            }
    
        }
    
    }

  • #2
    Regular Coder
    Join Date
    Mar 2006
    Posts
    725
    Thanks
    35
    Thanked 132 Times in 123 Posts
    You do not tell us if the code works in any browser, nor do you say where x comes from. It must be a global node list...

  • #3
    New Coder
    Join Date
    Feb 2011
    Posts
    23
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Hi,

    Sorry the code works in all browsers except IE. X is the length of an XML file but the problem is not related to that. I have just figured out that it is to do with the date aspect of the above code. If I remove the "date" parts the code works although I need the date section :-(. Therefore, the problem is within these parts of the code

    var d = new Date();

    var curr_date = d.getDate();

    if (curr_date < 10)

    curr_date = "0" + curr_date;

    var curr_month = d.getMonth();

    curr_month++;

    if (curr_month < 10)

    curr_month = "0" + curr_month;

    var curr_year = d.getFullYear();

    //alert("date="+curr_date+" month="+curr_month+" year="+curr_year);

    or it could be the following section

    if(curr_month==month && curr_year==year){

    document.getElementById("member").appendChild(newa);}

  • #4
    New Coder
    Join Date
    Feb 2011
    Posts
    23
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Also I have only pasted the relevant function above so there is code missing. The entire code would be confusing as the problem lies within the date parts of this function

  • #5
    New Coder
    Join Date
    Feb 2011
    Posts
    23
    Thanks
    4
    Thanked 0 Times in 0 Posts
    I think it might be this part that isn't working, does anyone know why?

    if(curr_month==month && curr_year==year){

    document.getElementById("member").appendChild(newa);}

  • #6
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    The nodeValue returns a string/ text value.

    Code:
    month = (date.getElementsByTagName("month")[0].childNodes[0].nodeValue);
    month = parseInt(month); // convert to a number - do the same for month.
    Code:
    membershipstatus = (x[i].getElementsByTagName("membership_status")[0].childNodes[0].nodeValue);
    Are you inventing your own tag names? Perhaps you're using XHTML?

    If you only have one element 'membership_status' then give it this id and use 'getElementById'.
    Is the value you need within the first child of the element? Depending on the type of element it is some browsers can insert hidden text nodes or elements.


  •  

    Tags for this Thread

    Posting Permissions

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