I have added some new code to the toggleDiv() javascript function. This code hides dispplay of all divs on the page - either diplayed or hidden(see my previous post).
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.js"> </script>
<script type="text/javascript" >
function toggleDiv(divId) {
// ***** NEW CODE *****
// number of forms (you can set that programatically)
var numberOfForms = 2;
// variable for storing each div's ID
var fmDivId = '';
// first loop through al forms and hide their divs
for(var i= 1; i <= numberOfForms; i++) {
// current form's ID
// (suppose your divs have IDs like form1, form2...)
fmDivId = 'form' + i.toString();
// set display to none
document.getElementById(frmDivId).style.display == 'none';
}
// ***** END OF NEW CODE *****
var el = document.getElementById(divId);
if(el.style.display == 'none') {
el.style.display = 'block';
} else {
el.style.display = 'none';
}
}
</script>
</head>
<body>
<a href="#" onclick="toggleDiv('form1');">Form 1</a>
<a href="#" onclick="toggleDiv('form2');">Form 2</a>
<div id="form1" style="display:none;">
<form >
Name<input type="text" />
</form>
</div>
<div id="form2" style="display:none;">
<form>
Surname<input type="text" />
</form>
</div>
<br />
</body>
</html>