Qualcosa del genere?
codice:
<html>
<head>
<style>
.fields {
display: none;
}
</style>
<script type="text/javascript">
function printResult() {
var selectedVal = document.forms[0].list.options[document.forms[0].list.selectedIndex].value;
var fieldGroups = document.getElementsByClassName("fields");
for (var i = 0; i < fieldGroups.length; i++) {
fieldGroups[i].style.display = "none";
}
document.getElementById("fields" + selectedVal).style.display = "block";
document.getElementById("showResult").innerText = "Your number is: " + selectedVal;
return false; //dont submit the form
}
</script>
</head>
<body>
<form action="" onSubmit="return printResult(this);">
<select name="list" onChange="printResult();">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<div id="fields1" class="fields">
<input type="text" value="Field 1 of group 1">
<input type="text" value="Field 2 of group 1">
</div>
<div id="fields2" class="fields">
<input type="text" value="Field 1 of group 2">
<input type="text" value="Field 2 of group 2">
</div>
<div id="fields3" class="fields">
<input type="text" value="Field 1 of group 3">
<input type="text" value="Field 2 of group 3">
</div>
<input type="submit" value="Submit">
</form>
<span id="showResult"></span>
</body>
</html>