I have this simple form:
<form method="post" action="index.php" >
<table>
<tr>
<td>
Sex:
</td>
<td>
<select name="sex" >
<option value="e">Select </option>
<option value="girl">Girl </option>
<option value="boy">Boy </option>
</select>
</td>
</tr>
<tr>
<td>
Accessories:
</td>
<td>
<select name="earrings" >
<option value="e">Select </option>
<option value="gold">gold </option>
<option value="silver">silver </option>
</select>
</td>
</tr>
</table>
<br>
<input type="submit" size="10" value="Go" name="go">
</form>
and I want that when I click on "boy" in the first select then this block have to dissapears:
<tr>
<td>
Accessories:
</td>
<td>
<select name="earrings" >
<option value="e">Select </option>
<option value="gold">gold </option>
<option value="silver">silver </option>
</select>
</td>
</tr>
I can do this with CSS ? If not, I can do this with javascript ?
The hidden attribute hides the <select> element. You can specify either 'hidden' (without value) or 'hidden="hidden"'. Both are valid. A hidden <select> element is not visible, but it maintains its position on the page.
The hidden global attribute is a Boolean attribute indicating that the element is not yet, or is no longer, relevant. For example, it can be used to hide elements of the page that can't be used until the login process has been completed. Browsers won't render elements with the hidden attribute set.
To hide an element, set the style display property to “none”.
You can't do this in CSS, but you can in JavaScript
function hide(){
var earrings = document.getElementById('earringstd');
earrings.style.visibility = 'hidden';
}
function show(){
var earrings = document.getElementById('earringstd');
earrings.style.visibility = 'visible';
}
Just make sure that your td
has id=earringstd
Then create function:
function genderSelectHandler(select){
if(select.value == 'girl'){
show();
}else if(select.value == 'boy'){
hide();
}}
Now all you have to is change your gender select tag to:
<select name="sex" onchange="genderSelectHandler(this)">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With