Inaccessible
Inaccessible

Reputation: 1560

document.getElementByClassName is doen't work properly

$('.inlineDatepickerDepart').datepick({ minDate: '<%=@start_display%>', maxDate: '<%=@end_display%>',
   monthsToShow: 2,
  dateFormat: "dd/mm/yyyy",
  onSelect: function(date) {    

var selected=parseInt(document.getElementById("guest_adult").value)+parseInt(document.getElementById("guest_kid").value); alert(selected);

for(var x=0;x<selected;x++)
{
document.getElementsByClassName("depart1")[x].innerHTML = '2012-03-24';
document.getElementsByClassName("return1")[x].innerHTML = '2012-04-24';
}
},
});

The alert shows the no of guests.It replaces value of depart1[0] alone.Not for the entire loop and 'return1' class too. can any one give me key to solve it

Upvotes: 0

Views: 127

Answers (4)

Inaccessible
Inaccessible

Reputation: 1560

Finally it works by using following codes.

var a;
var b;
for(var x=0;x<selected;x++)
{
a=document.getElementsByClassName("depart1")[x];
a.innerHTML = depart_date;
b=document.getElementsByClassName("return1")[x];
b.innerHTML = return_date;
}

Upvotes: 0

Sanober Malik
Sanober Malik

Reputation: 2805

You should use :

getElementsByClassName

Because there can be more than one elements with same class applied so it's plural.

Upvotes: 2

Denys S&#233;guret
Denys S&#233;guret

Reputation: 382112

You should look at the console to catch basic errors, like the fact the getElementByClassName function doesn't exist.

Use getElementsByClassName instead.

Upvotes: 3

Blender
Blender

Reputation: 298126

It's plural:

document.getElementsByClassName
                   ^

Upvotes: 2

Related Questions