user1550575
user1550575

Reputation: 55

How can we set the value to a div dynamically

Can any one tell me the theat how can i set the value to the DIV TAG DYNAMICALLY USING javascript

<div class="sD" style="width:55px;" id="CYearHold">
    Here i have to display Current year
</div>      
<select id="CYear" class="inputControl simple" style="width:55px;" name="currentYear" onChange="setYear1(this);">
</select>

Upvotes: 0

Views: 5696

Answers (2)

guillaume
guillaume

Reputation: 7177

get the current year

select = document.getElementById("CYear");
year = select.options[select.selectedIndex].innerHTML;

set it in your div

document.getElementById("div.sd").innerHTML=year;

Upvotes: 0

psx
psx

Reputation: 4048

You can use innerHTML:

document.getElementById('CYearHold').innerHTML = 'something';

If you want to put the selected year in the div, you can do this:

var e = document.getElementById("CYear");
var strYear = e.options[e.selectedIndex].value;
document.getElementById('CYearHold').innerHTML = strYear;

Upvotes: 2

Related Questions