JSFiddle - React, Tailwind, and code Playground
HTML
<form action="" accept-charset="UTF-8" method="post" id="subscribe">
<div>
<p>Subscribe to our mailing list, and be among the first to hear about our
concerts and other events.</p>
<div id="errors"></div>
<div class="form-item">
<label for="name">Your name: <span class="form-required" title="This field is required.">*</span>
</label>
<input type="text" maxlength="255" name="name" id="name" size="60" value=""
class="form-text required" />
</div>
<div class="form-item">
<label for="method">Send me:</label> <span id="method">
<label class="inline"><input type="radio" class="radio" name="method" value="E-mail" checked="checked"/> E-mail </label>
<label class="inline"><input type="radio" class="radio" name="method" value="Postal Mail"/> Postal Mail </label>
<label class="inline"><input type="radio" class="radio" name="method" value="Both"/> Both </label>
</span>
</div>
<div class="form-item email">
<label for="email">Your e-mail address: <span class="form-required" title="This field is required.">*</span>
</label>
<input type="email" maxlength="255" name="email" id="email" size="60"
value="" class="form-text required" />
</div>
<div class="form-item postal">
<label for="name">Address: <span class="form-required" title="This field is required.">*</span>
</label>
<input type="text" maxlength="255" name="address" id="address" size="60"
value="" class="form-text" />
<br/>
<input type="text" maxlength="255" name="address_2" id="address_2" size="60"
value="" class="form-text" />
</div>
<div class="form-item postal">
<label for="name">City: <span class="form-required" title="This field is...
CSS
.form-item {
margin: 1em 0;
}
JavaScript
var postal = $$('.postal'), email = $$('.email'), method;
var setup = function(evt){
if(evt && evt.element().name == 'method') $('errors').update();
method = $$('input[name="method"]:checked').first();
if(method){
switch($F(method)){
case 'E-mail':
postal.invoke('hide').each(function(d){d.select('input').invoke('disable')});
email.invoke('show').each(function(d){d.select('input').invoke('enable')});
break;
case 'Postal Mail':
postal.invoke('show').each(function(d){d.select('input').invoke('enable')});
email.invoke('hide').each(function(d){d.select('input').invoke('disable')});
break;
default:
postal.invoke('show').each(function(d){d.select('input').invoke('enable')});
email.invoke('show').each(function(d){d.select('input').invoke('enable')});
break;
}
}
}
setup();
document.observe('click', setup);