Link to home
Start Free TrialLog in
Avatar of Animaze
AnimazeFlag for United States of America

asked on

Toggle Show/Hide Element that is sibling of Checkbox with JQuery

Hi,

Looking for a JQuery solution to this -
I have a series of HTML checkboxes and each has a hidden element (<ul class="product-status-options-controls">) associated with it. When a checkbox is checked I would like to show the element associated with that checkbox, while the others remain hidden. If another checkbox is selected the current hides and the new one is visible.

Below is the basic HTML. So, on page load, the "product-status-options-controls" class is hidden. When a checkbox under the class "product-status-options" is checked, that checkbox's corresponding "product-status-options-controls" element is visible. It will hide again if another checkbox is selected and the new checkbox's  "product-status-options-controls" element becomes  visible.

<form action="#" method="post">
<fieldset>
<legend>Add Product</legend>
<ul class="product-status-options">
	<li>
	<input type="checkbox" name="status_welcome" id="status_welcome" value="1" /> 
	<label for="status_welcome">Welcome</label>
	<ul class="product-status-options-controls">
		<li>
		<label for="status_welcome_notes">Note:</label><br />
		<textarea name="status_welcome_notes" id="status_welcome_notes" cols="25" rows="4"></textarea>
		</li>
		
		<li>
		<input type="submit" value="Update"/>
		</li>
	</ul>
	</li>
	
	<li>
	<input type="checkbox" name="status_preproduction" id="status_preproduction" value="1" /> 
	<label for="status_preproduction">Pre-Production</label>
	<ul class="product-status-options-controls">
		<li>
		<label for="status_preproduction_notes">Note:</label><br />
		<textarea name="status_preproduction_notes" id="status_preproduction_notes" cols="25" rows="4"></textarea>
		</li>
		
		<li>
		<input type="submit" value="Update"/>
		</li>
	</ul>
	</li>
	
	<li>
	<input type="checkbox" name="status_production" id="status_production" value="1" /> 
	<label for="status_production">Production</label>
	<ul class="product-status-options-controls">
		<li>
		<label for="status_production_notes">Note:</label><br />
		<textarea name="status_production_notes" id="status_production_notes" cols="25" rows="4"></textarea>
		</li>
		
		<li>
		<input type="submit" value="Update"/>
		</li>
	</ul>
	</li>
	
	<li>
	<input type="checkbox" name="status_shipped" id="status_shipped" value="1" /> 
	<label for="status_shipped">Shipped</label>
	<ul class="product-status-options-controls">
		<li>
		<label for="status_shipped_notes">Note:</label><br />
		<textarea name="status_shipped_notes" id="status_shipped_notes" cols="25" rows="4"></textarea>
		</li>
		
		<li>
		<input type="submit" value="Update"/>
		</li>
	</ul>
	</li>
</ul>
</fieldset>
</form>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Animaze

ASKER

Thanks for the excellent examples. Was easily able to understand and implement it.
Thank you and you are most welcome