kuttan pillai kuttan pillai - 23 days ago 12
Javascript Question

Jquery Code not working when placed in head tag

i have some jquery code which doesn't work when placed inside the head tag but works when placed after the body tag. Even though it is inside document.ready() it isn't working.

Here is my code:

$(document).ready(function() {
for (i = 1950; i <= new Date().getFullYear(); i++) {
$('#from').append($('<option />').val(i).html(i));
$('#to').append($('<option />').val(i).html(i));
}
})


Here is my Structure

< head>

<script type="text/javascript" src="scripts/jquery/js/jquery-1.4.2.min.js"></script>

<script type="text/javascript" src="scripts/jquery/js/jquery-ui-1.8.17.custom.min.js"></script>

<script type="text/javascript" src="/easyoffice/js/excelExport.js"></script>
<script type="text/javascript" src="/easyoffice/js/tinytable.js"></script>

<script type="text/javascript">
$(document).ready(function() {
for (i = 1950; i <= new Date().getFullYear(); i++) {
$('#from').append($('<option />').val(i).html(i));
$('#to').append($('<option />').val(i).html(i));

}

})
function checkyear() {
var from = $('select[id=to]').val();
var to = $('select[id=from]').val();
if (from == 'Select' || to == 'Select') {
alert(" Please Select an Year ")
return false;
} else if (from <= to) {

alert(" Please Select an Year greater than From Year ")
$("select#to").prop('selectedIndex', 0);

return false;
} else {
return true;
}
}

</script>
</head>

Answer

I Figured Out What was the problem. i put the ready function after the tag and now it is working perfectly

Comments