Forum Moderators: open
I think BlobFisk meant something like this:
<script type="text/javascript">
<!--
//this function checks the value of the selected option and hides/shows the login div based on this
function checkResponse(obj){
if(obj.options[obj.selectedIndex].value=='Yes'){
//show the div
document.getElementById('loginDiv').style.display="block"
}else{
//hide the div
document.getElementById('loginDiv').style.display="none"
}
}
//-->
</script>
<select id="mySelect" onchange="checkResponse(this)">
<option value="Yes">Yes</option>
<option value="No">No</option>
</select>
<div id="loginDiv" style="display:none;">
<p>Username: <input type="text" name="username" size="30" /></p>
<p>Password: <input type="password" name="userpass" size="30" /></p>
</div>
When the user changes the select, it fires the checkResponse() function, which gets the value of the selected index and shows/hides the login div based on the response ('Yes' shows, 'No' hides) by changing the style display type.
ajkimoto
Essentially, this script loads a different page into an iframe based on the selected option using the switch control structure.
Just create a separate case in the switch for each login type from the select object and a separate login page for each case in the switch.
Probably a better way to go if you are going to have increasing numbers of login pages would be to build the page dynamically using some kind of server-side code. You could also have just one js_login.htm page, built differently based on parameters passed to it from this page...
<script type="text/javascript">
<!--
//this function checks the value of the selected option and changes the src of the iframe to the appropriate page.
function checkResponse(obj){
var curOpt=obj.options[obj.selectedIndex].value
//switch allows branching based on value of curOpt
switch (curOpt){
case 'login1':
//set src of iframe to js_login1.htm
document.getElementById('myFrame').src="js_login1.htm"
break;
case 'login2':
//set src of iframe to js_login2.htm
document.getElementById('myFrame').src="js_login2.htm"
break;
case 'login3':
//set src of iframe to js_login3.htm
document.getElementById('myFrame').src="js_login3.htm"
break;
default:
//default empty src for iframe
document.getElementById('myFrame').src="";
}
}
//-->
</script>
<style type="text/css">
</style>
</head>
<body>
<select id="mySelect" onchange="checkResponse(this)">
<option value="">Choose Login</option>
<option value="login1">login1</option>
<option value="login2">login2</option>
<option value="login3">login3</option>
</select>
<br />
<iframe frameborder="0" style="border:0;" id="myFrame" src=""></iframe>
</body>
ajkimoto