I was wondering if anyone wanted to take a shot at re-factoring my code. I am not a javascript guru, and I would like some feedback on what I could do to make it better.
The below code shows/hides the top div, and when the top div is hidden, the bottom div takes up the space of the top div.
Thanks,
bulagump
<!DOCTYPE HTML>
<head>
<script>
function DivToggle (vTopDiv,vBottomDiv)
{
var vBottomDivHeight;
if ( parseInt(document.getElementById(“vBottomDivHeight”).value)>0) {
vBottomDivHeight = parseInt(document.getElementById(“vBottomDivHeight”).value);
}
else{
// when the page loads for the first time, put the height of the AJAX div in a hidden input field
vBottomDivHeight = parseInt(document.getElementById(vBottomDiv).style.height);
document.getElementById(“vBottomDivHeight”).value=vBottomDivHeight;
document.getElementById(“vTopDivExpandedFlag”).value=”Y”;
}
// if the Top Div is displayed, hide it and increase the size of the bottom Div by the height of the top Div
if (document.getElementById(“vTopDivExpandedFlag”).value===”Y” )
{
vBottomDivHeight += parseInt(document.getElementById(vTopDiv).style.height);
document.getElementById(vBottomDiv).style.height = vBottomDivHeight+ ‘px’;
document.getElementById(vTopDiv).style.display = “none”;
document.getElementById(“vTopDivExpandedFlag”).value=”N”;}
else {
// if the databrowser div is hidden, display it and reset the AJAX div to the original size
document.getElementById(vBottomDiv).style.height = vBottomDivHeight+ ‘px’;
document.getElementById(vTopDiv).style.display = “”;
document.getElementById(“vTopDivExpandedFlag”).value=”Y”;
}
}
</script>
</head>
<body>
<input type=”hidden” id=”vBottomDivHeight”></input>
<input type=”hidden” id=”vTopDivExpandedFlag”></input>
<a href=”#” onclick=”javscript?ivToggle(‘testdiv’,’testdiv2′);” >show/hide top div, and grant the bottom div the space that the top div was
taking up</a>
<div style=”height: 300px; background-color:lightblue;” id=”testdiv”>
</div>
<div style=”height: 130px; overflow:scroll; background-color:gray;” id=”testdiv2″>
bottom div row 1 <br>
bottom div row 2 <br>
bottom div row 3 <br>
bottom div row 4 <br>
borrom div row 6 <br>
borrom div row 7 <br>
borrom div row 8 <br>
borrom div row 9 <br>
borrom div row 10 <br>
borrom div row 11 <br>
borrom div row 12 <br>
borrom div row 13 <br>
borrom div row 14 <br>
borrom div row 15 <br>
borrom div row 16 <br>
borrom div row 17 <br>
</div>
</body>
</html>