The real value of something like this would be to redirect server side (where forms have their real power) on the basis of the submitted value with no javascript involved. However, here is an interesting example of something that could be done with javascript:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>BOY GIRL</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function getQval(n, m) {
/*my n=name, m=searchString(optional)*/
if(!arguments[0]||typeof n!='string')
return null;
var r=new RegExp('[?&;]'+n+'=([^&;#]*)'), m=arguments[1]?m:location.search;
return (m=r.exec(m))? unescape(m[1]) : null;
}
function showHide(v){
var c=v=='boy'? 'girl' : v=='girl'? 'boy' : 'boygirl';
document.write('<style type="text/css">.'+c+' {display:none;}<\/style>')
if(v)
document.title=v.toUpperCase();
}
showHide(getQval('boygirl'));
</script>
</head>
<body>
<form action="#">
<div class="boy girl">
Boy <input name="boygirl" value="boy" type="radio"><br>
Girl <input name="boygirl" value="girl" type="radio"><br>
<br>
<input value="Continue" type="submit">
</div>
</form>
<div class="boygirl">
<div class="boy">It's a Boy!</div>
<div class="girl">It's a Girl!</div>
</div>
</body>
</html>
Bookmarks