How a checkbox will trigger another input element in html via javascript?
Tags: javascript,html,css,checkbox,visibility
Problem :
I have two input checkboxes as well as two text fields:
HTML:
<form action="">
<label for="male">Male</label>
<input onchange="genderCheck()" type="checkbox" checked="checked" name="sex" id="male" value="male"><br>
<label for="female">Female</label>
<input onchange="genderCheck()" type="checkbox" name="sex" id="female" value="female">
<span id="spanIban">
<br><label for="iban">IBAN:</label>
<input type="text" name="mIban" id="iban">
</span>
<span id="spanBust"><br><label for="bust">Bust:</label>
<input type="text" name="fBust" id="bust"></span>
</form>
I made the first checkbox checked by default as well as the first text field visible: CSS
#spanBust{visibility:hidden;}
#spanIban{visibility:visible;}
I would like it to do the following: When some of those checkboxes are triggered/untriggered the textareas below to do it as well (through visibility). Javascript:
var check = document.getElementById("male").defaultChecked;
function genderCheck(){
if(document.getElementById("male").checked == true)
{
document.getElementById("spanIban").style.visibility="visible";
document.getElementById("spanbBust").style.visibility="hidden";
}
else if(document.getElementById("female").checked == true)
{
document.getElementById("spanIban").style.visibility="hidden";
document.getElementById("spanBust").style.visibility="visible";
}
else{ document.getElementById("spanIban").style.visibility="hidden"; document.getElementById("spanBust").style.visibility="hidden";}
}
I have done something wrong and have no idea how to clear up the things or rather the whole algorithm is wrong.
Solution :
You have a few typos in your code, otherwise it kinda works. You can help reduce these and also improve performance by stashing all your lookups in variables. The logic also does not seem quite right, you want the female checkbox only to toggle if the male is not checked? Anyway, here is a new version:
function GenderCheck(){
var checkMale = document.getElementById("male"),
checkFemale = document.getElementById("female"),
iban = document.getElementById("spanIban"),
bust = document.getElementById("spanBust");
iban.style.visibility = (checkMale.checked ? "visible" : "hidden");
bust.style.visibility = (checkFemale.checked ? "visible" : "hidden");
}
CSS Howto..
No, this is perfectly fine, and actually may be a best practice for background images. Moving the image declarations into the style sheet means the images may be downloaded a...
You need to be more specific. .portfolio-menu li a is more specific than .list-click and so it will always win no matter what order you place it in the style...
You can do it with css like this: .box , .appear{ background: #151515; height: 100px; width: 100px; float:left; } .appear{ background:red; display:none } .box:hover{ background: #e6e6e6; height: 100px; width: 100px;...
That white line is a space character that is placed between the divs. <div class="left">TODO write content1</div> <--This new line is considered a space--> <div class="left">TODO write content2</div> Remove it...
Make sure to use Font.loadFont to actually load the font on application startup. Then you should be able to use the font from CSS. Be careful to use the font's...
Not sure if this is kind of what you're looking for. Question seemed a bit unclear. http://jsfiddle.net/KacPY/1/...
The Web Developer plugin for Firefox and Chrome is able to do this Once you have installed the plugin the option is available in the CSS menu. For example, CSS...
Add the shadow to a :before pseudo element or an empty div. For foolproof z-index you can also wrap the map in an additional div. #map { position: relative; z-index:...
ul.dropdown { background: #000 url(../images/menuLight.png) repeat-x top left; }
You can insert a link element via jQuery, which points to your external css file like this: $('head').append($('<link rel="stylesheet" type="text/css" />').attr('href', 'external-css-stylesheet-url-goes-here')); ...
You can set the height of the page using jquery $(function() { $('.fullLength') .css({'height': (($(window).height()) -72)}); $(window).bind('resize', function(){ $('.fullLength') .css({'height': (($(window).height()) -72)}); }); }); For the width just set it...
IDs MUST be unique. Use a class instead. Additionally, don't use jQuery for this. CSS: .text:hover {color:#000} DEMO Here's a jsFiddle to demonstrate... Using RED in the fiddle to see...
CSS how to get the: a img on top, insted of the first a href “
”without floating
I found another way of doing this: <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <style> ul {list-style: none; margin: 0; padding: 0;} li {position: relative; overflow: hidden;} a {display: block;}...
You can try like this - * { box-sizing: border-box; } .container { position: relative; height: 256px; width: 256px; } .inner { float: left; margin-right: 16px; border: solid 1px red;...
There are a couple of things first of all you are specifying div.left therefore the class on table never inherits any properties from it's class name of left. Secondly table...
You can just add css rules to the classes after the bootstrap css rules. Be aware that bootstrap uses box-sizing: border-box; for all elements, which might cause your improper alignment....
I'd recommend something like this: div.center-img { background:url('/path/img.jpg') center center no-repeat; } But your question would be answered with something like this: $('div img').each(function() { if( this.width > 240 )...
You can get the current style of an element with this: var elem = ...; var css = document.defaultView ? document.defaultView.getComputedStyle(elem, null) : elem.currentStyle; if ('length' in css) { //...
You should be able to access the Style element by using someUiObject.getElement().getStyle() and then manipulate the style there....
I've dealt a lot with CSS themes as of late. Here is the approach I am using. The base themes a, b, c, d, I've left alone for the most...
You can use css text-align to achieve what you want. text-aligh: right on the left hand <div> and text-align: left on the right hand <div>. As @Manish mentioned, I also...
Since you specifically tagged this CSS3, try using CSS3! body>:not(.printing) { display: none; } This should work for the example you gave. I hope it works for your real-world application!...
Pass a parameter in anchor tag and check in the second page EXAMPLE BELOW First Page <a href="test.php?hide=div2"><input type="button" name="button" value="Click Here" /></a> Second Page <?php $hide = isset($_REQUEST['hide']) ?...
So it turns out ionic have platform classes baked into the body class already, nice and easy. All I had to do was select on .platform-ios { } here is...
You need to increase the border thickness ----> border-left: 103px solid transparent; and border-right: 100px solid transparent; and do some positioning adjustments. For displaying a specific region of an image,...
Alright, so there are obviously not a whole lot of people who have tried the .NET 4 menu as of today. Not surprising as the final version was released a...
As you can see here the "div that contains floated elements" is actually in the center (red). I am assuming you want to center the floating elements themselves, not their...
Have you tried the following : How to define bold, italic using @font-face ? The @font-face property allows you to specify for which styles to apply the font....
You can't center an absolutely positioned element with an unknown width, so here's a workaround. See: http://jsfiddle.net/thirtydot/xv9Wq/25/ CSS: #headerBanner { text-align: center; width: 100%; position: absolute; top: 40px; z-index: 2;...
Try: .song-links { letter-spacing: 1px; list-style: none; color: black; } .song-selector { display: inline; margin-left: 8px; visibility: hidden; } .song-links li:hover .song-selector { visibility: visible; } ...