Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-17-2011, 04:42 PM   PM User | #1
NKeuxmuis
New Coder

 
Join Date: Feb 2011
Posts: 23
Thanks: 4
Thanked 0 Times in 0 Posts
NKeuxmuis is an unknown quantity at this point
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);
        }

    }

}
NKeuxmuis is offline   Reply With Quote
Old 04-17-2011, 04:51 PM   PM User | #2
mrhoo
Regular Coder

 
Join Date: Mar 2006
Posts: 708
Thanks: 30
Thanked 127 Times in 118 Posts
mrhoo will become famous soon enoughmrhoo will become famous soon enough
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...
mrhoo is offline   Reply With Quote
Old 04-17-2011, 05:02 PM   PM User | #3
NKeuxmuis
New Coder

 
Join Date: Feb 2011
Posts: 23
Thanks: 4
Thanked 0 Times in 0 Posts
NKeuxmuis is an unknown quantity at this point
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);}
NKeuxmuis is offline   Reply With Quote
Old 04-17-2011, 05:03 PM   PM User | #4
NKeuxmuis
New Coder

 
Join Date: Feb 2011
Posts: 23
Thanks: 4
Thanked 0 Times in 0 Posts
NKeuxmuis is an unknown quantity at this point
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
NKeuxmuis is offline   Reply With Quote
Old 04-17-2011, 05:22 PM   PM User | #5
NKeuxmuis
New Coder

 
Join Date: Feb 2011
Posts: 23
Thanks: 4
Thanked 0 Times in 0 Posts
NKeuxmuis is an unknown quantity at this point
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);}
NKeuxmuis is offline   Reply With Quote
Old 04-17-2011, 05:26 PM   PM User | #6
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
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.
AndrewGSW is offline   Reply With Quote
Reply

Bookmarks

Tags
ie7, internet explorer, javascript, not working

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:35 PM.


Advertisement
Log in to turn off these ads.