Toby Cannon
Toby Cannon

Reputation: 735

Change Marquee Content Using Javascript

Before anyone says, I know there are better ways than using a marquee, however, for this instance I am using one.

Depending on the date, I want the marquee to say a different thing. Why is the marquee not changing and always saying default?

Javascript

var d = new Date();
var n = d.getDate();

if (n > 0 && n < 8){
	var bday ="Birthday Kids name and age 1"
	}else if(n > 7 && n < 15){
		var bday ="Birthday Kids name and age 2"
	}else if(n > 14 && n < 22){
		var bday ="Birthday Kids name and age 3"
	}else if(n > 21 && n < 29){
		var bday ="Birthday Kids name and age 4"
	}else if(n > 28 && n < 32){
		var bday ="BirthdayKids name and age 5"
	}
	
document.getElementById("birthdays").textContent = "We wish a very happy birthday to "+bday;
<marquee bgcolor="#088A08" id="birthdays" direction="left" loop="20" width="100%">Default</marquee>

Upvotes: 0

Views: 558

Answers (2)

rkamath
rkamath

Reputation: 26

try

 document.getElementById("birthdays").innerHTML

edit: replace == with = and make sure the getElementById is called after the element or after the page is loaded

Upvotes: 0

Lal
Lal

Reputation: 14810

See the fiddle

Javascript

var d = new Date();
var n = d.getDate();
if (n > 0 && n < 8){
    var bday ="Birthday Kids name and age 1";
    }else if(n > 7 && n < 15){
        var bday ="Birthday Kids name and age 2";
    }else if(n > 14 && n < 22){
        var bday ="Birthday Kids name and age 3";
    }else if(n > 21 && n < 29){
        var bday ="Birthday Kids name and age 4";
    }else if(n > 28 && n < 32){
        var bday ="BirthdayKids name and age 5";
    }

document.getElementById("birthdays").textContent ="We wish a very happy birthday to "+bday;

Notice that i've removed the == from your code which solves the problem as there is a problem with the syntax error.

== is used for comparisons and for assignments just = is used..

Upvotes: 1

Related Questions