Register and join over 40,000 other developers!
Recent Topics
-
The Game You Are Waiting For?
WendellHarper - Dec 06 2020 01:21 PM
-
Quora and Reddit Backlinks
WendellHarper - Dec 06 2020 01:14 PM
-
Delete account
pindo - Jul 23 2020 01:33 AM
-
Print specific values from dictionary with a specific key name
Siten0308 - Jun 20 2019 01:43 PM
-
Learn algorithms and programming concepts
johnnylo - Apr 23 2019 07:49 AM
Recent Blog Entries
Recent Status Updates
Popular Tags
- networking
- Managed C++
- stream
- console
- database
- authentication
- Visual Basic 4 / 5 / 6
- session
- Connection
- asp.net
- import
- syntax
- hardware
- html5
- array
- mysql
- java
- php
- c++
- string
- C#
- html
- loop
- timer
- jquery
- ajax
- javascript
- programming
- android
- css
- assembly
- c
- form
- vb.net
- xml
- linked list
- login
- encryption
- pseudocode
- calculator
- sql
- python
- setup
- help
- game
- combobox
- binary
- hello world
- grid
- innerHTML

Help with code[checkbox.checked && div id(hide || show)]
Started by bluefenix, Aug 13 2012 01:06 PM
checkbox div hide show hide element show element hide div show div checkbox.checked
1 reply to this topic
#1
Posted 13 August 2012 - 01:06 PM
Hello everybody, Im working on a project and I want that when clicked on the "national" checkbox the country div shows and the europe div hides and when clicked on the international happens the other way around. In my effort of achieving this, Ive wrote this code, though it doesnt work. Can anybody tell me what did I do wrong or how should I pursue this?
<body>
<div><div><form id= "form1">
<input type="checkbox" name="option3" value="national" id= 'national' onchange= "f()"> National</input>
<input type="checkbox" name="option4" value="internacional" id= 'inter' onchange= "f()"> International</input>
<input type="button" value="check" onclick="f()">
</form>
</div>
<script type= "text/javascript">
var nation= document.getElementById("national");
var international= document.getElementById("inter");
var country= document.getElementById("country");
var europe= document.getElementById("europe");
function f()
{
if (nation.checked= true) &&(international.checked= false)
{ country.style.display='block';
europe.style.display='none'; }
else if (nation.checked= true) &&(international.checked= false)
{ country.style.display='none';
europe.style.display='block'; }
else if (international.checked= true) &&(nation.checked= true)
{ country.style.display='none';
europe.style.display='none';
alert("Dont select both at the same time.")}
else
{ peru.style.display='none';
europe.style.display='none'; }}
</script>
<!--This div only appears if national its selected
-->
<div id= 'country'>
<form id= 'regiones'method= 'POST'>
<select id= 'selection'>Uno
<option>Uno</option>
<option>Due</option>
</select>
</form>
</div>
<!-- This div only appears if international its selected
-->
<div id= "europe">
<form id= 'Europea'method= 'POST'>One
<select id= 'sel1'>
<option>One</option>
<option>Two</option>
</select>
</form>
</div> </div>
</body>
<body>
<div><div><form id= "form1">
<input type="checkbox" name="option3" value="national" id= 'national' onchange= "f()"> National</input>
<input type="checkbox" name="option4" value="internacional" id= 'inter' onchange= "f()"> International</input>
<input type="button" value="check" onclick="f()">
</form>
</div>
<script type= "text/javascript">
var nation= document.getElementById("national");
var international= document.getElementById("inter");
var country= document.getElementById("country");
var europe= document.getElementById("europe");
function f()
{
if (nation.checked= true) &&(international.checked= false)
{ country.style.display='block';
europe.style.display='none'; }
else if (nation.checked= true) &&(international.checked= false)
{ country.style.display='none';
europe.style.display='block'; }
else if (international.checked= true) &&(nation.checked= true)
{ country.style.display='none';
europe.style.display='none';
alert("Dont select both at the same time.")}
else
{ peru.style.display='none';
europe.style.display='none'; }}
</script>
<!--This div only appears if national its selected
-->
<div id= 'country'>
<form id= 'regiones'method= 'POST'>
<select id= 'selection'>Uno
<option>Uno</option>
<option>Due</option>
</select>
</form>
</div>
<!-- This div only appears if international its selected
-->
<div id= "europe">
<form id= 'Europea'method= 'POST'>One
<select id= 'sel1'>
<option>One</option>
<option>Two</option>
</select>
</form>
</div> </div>
</body>
#2
Posted 13 August 2012 - 10:18 PM
You're not checking if it equals true. You set it to true there.if (nation.checked= true)
To check if it equals you need 2 or 3(more strict) equal signs.
Or in case of true/false:
if(nation.checked)
Also tagged with one or more of these keywords: checkbox, div, hide, show, hide element, show element, hide div, show div, checkbox.checked
![]() Save checkboxes to SQLite DatabaseStarted by DarkHeart, 26 Mar 2015 ![]() |
|
![]() |
||
Language Forums →
HTML, CSS and Javascript →
Is it possible: Float top div on CSS3?Started by PuddingEatsPanda, 01 Jul 2014 ![]() |
|
![]() |
||
Language Forums →
PHP →
question in phpStarted by Asom, 24 May 2014 ![]() |
|
![]() |
||
Language Forums →
HTML, CSS and Javascript →
Duplicated text because of jQuery mobile - how to hide?Started by elliottveares, 25 Apr 2014 ![]() |
|
![]() |
||
Language Forums →
C# →
C# adding "focus" to a checkbox windows formsStarted by rubbadrools, 02 Apr 2014 ![]() |
|
![]() |
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download