I was created a table with <table> tag and id is 'calendarid'. In this each td contains a textbox and an image. Some textboxes contain value and some are empty. I want to hide the image where textbox contains no value(or empty).I have used following java script code to do this, but not working.Here all images are hiding with the following code.
var table = document.getElementById( 'calendarid' );
var inputs = table.getElementsByTagName( 'input' );
//get all inputs inside a table
for(var z=0;z<inputs.length;z++){
var input_id = String(inputs[z].id);
var splitVal = input_id.split("_");
var image_id = String(splitVal[0] + '_' + splitVal[2] + '_' + splitVal[1]);
var spentHrs = document.getElementById(input_id).value;
if(spentHrs == 0) {
document.getElementById(image_id).style.display = "none";
}
else { }
}
If I use alert then code is working fine(see below code). But I dont want to show alert. What is the reason for this behaviour ? and how to solve this?
var table = document.getElementById( 'calendarid' );
var inputs = table.getElementsByTagName( 'input' );
//get all inputs inside a table
for(var z=0;z<inputs.length;z++){
var input_id = String(inputs[z].id);
var splitVal = input_id.split("_");
var image_id = String(splitVal[0] + '_' + splitVal[2] + '_' + splitVal[1]);
var spentHrs = document.getElementById(input_id).value;
**alert(spentHrs);**
if(spentHrs == 0) {
document.getElementById(image_id).style.display = "none";
}
else { }
}