I’m working on a form for a quilting site and just started implementing a field-hiding jQuery script to get unnecessary fields out of the way.
When the user checks the Custom “quilt_style” radio button, it drops a custom field with slideToggle(). Lower on the page, the radio button set “cust_batting” toggles two different fields based on a yes or no choice.
Here’s the dilema…if the user goes to the “cust_batting” question first, everything works fine. If the user uses the “quilt_style” field first, the “cust_batting” field only slides up, but wont come down again. Here’s the jQuery script:
$(document).ready(function() {
// Hide fields that aren't needed yet
$('#cust_notes').hide();
$('#batt_type').hide();
$('#batt_purch').hide();
// On selecting the relevant radio/check, toggle additional fields
$('input[name="quilt_style"]').change(function() {
if ($('input[@name="quilt_style"]:checked').val() == 'Custom')
{
$('#cust_notes').slideToggle().addClass('tip');
}
else if ($('input[@name="quilt_style"]:checked').val() != 'Custom')
{
$('#cust_notes').slideUp();
}
});
$('input[name="cust_batting"]').change(function() {
if ($('input[@name="cust_batting"]:checked').val() == 'yes')
{
$('#batt_type').slideDown().addClass('tip');
$('#batt_purch').slideUp();
}
else if ($('input[@name="cust_batting"]:checked').val() == 'no')
{
$('#batt_purch').slideDown().addClass('tip');
$('#batt_type').slideUp();
}
else {
$('#batt_type').slideUp();
$('#batt_purch').slideUp();
}
});
});
And here are the relevant fields in the form, stripped of php goodies:
The upper fields “quilt_style”
<div class="quilt_select">
<label for="call_me">
<input type="radio" name="quilt_style" value="Contact customer" id="call_me">Contact me to discuss
</label>
<label for="ete_panto">
<input type="radio" name="quilt_style" value="E2E Pantograph" id="ete_panto">Edge to Edge Pantograph (starts at $.02/sq inch)
</label>
<label for="panto_cust_border">
<input type="radio" name="quilt_style" value="Panto Custom Border" id="panto_cust_border">Pantograph & Custom Borders (starts at $.02/sq in. + $10 per border)
</label>
<label for="custom">
<input type="radio" name="quilt_style" value="Custom" id="custom">Custom (starts at $.025 - $.035/sq in.)
</label>
</div>
<div id="cust_notes">
<label for="custom_notes">Notes for your custom quilt: </label>
<textarea name="custom_notes" id="custom_notes" rows="6" cols="40"></textarea>
</div>
The lower fields “cust_batting”:
<h5>Are you supplying your own batting?</h5>
<div class="radio">
<label for="cust_batting-yes">
<input type="radio" name="cust_batting" value="yes" id="cust_batting-yes">Yes
</label>
<label for="cust_batting-no">
<input type="radio" name="cust_batting" value="no" id="cust_batting-no">No
</label>
</div>
<div id="batt_type">
<label for="type_of_batting">Type of batting (* required if supplying your own)</label>
<input type="text" name="type_of_batting" id="type_of_batting">
</div>
<div id="batt_purch" class="radio">
<h5>Would you like to purchase our batting? (Hobbs Heirloom at only $8/yard!)</h5>
<label for="batting_purch-yes">
<input type="radio" name="batting_purch" value="yes" id="batting-purch-yes">Yes
</label>
<label for="batting_purch-no">
<input type="radio" name="batting_purch" value="no" id="batting_purch-no">No
</label>
</div>
You can go here for a working model, but the way it’s written, you’ll have to fill in some dummy info on the 1st page. The problem is on the 2nd page, but you can’t get there without filling in the 1st one.