Question

I have a table and a div in it. I have to resize both on load and on window resize.

These Javascript functions (resizeTable and resizeDiv) work if called separately, but resizeDiv doesn't work if called after resizeTable from autoResize.

<script>

function autoResize()
{
    var windowSize = document.documentElement.clientHeight;
    var tableHeight = windowSize * 0.9+'px';
    var rowHeight = (windowSize * 0.9 - 99 - 50)+ "px";
    resizeTable(tableHeight);
    resizeDiv(rowHeight);
}

function resizeTable(tableHeight)
{
    document.getElementById("mainTable") = tableHeight;
}

function resizeDiv(rowHeight)
{
    document.getElementById("cellLogin").style.height = rowHeight;
}

</script>
Was it helpful?

Solution

Well, I think you've got a bit of a mistake in your code. The line:

document.getElementById("mainTable") = tableHeight;

Should actually be:

document.getElementById("mainTable").style.height = tableHeight;

Here's a JSFiddle with the fixed code, seems to give you what you need. Let me know if you have any questions!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top