Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Help with code[checkbox.checked && div id(hide || show)]

checkbox div hide show hide element show element hide div show div checkbox.checked

  • Please log in to reply
1 reply to this topic

#1 bluefenix

bluefenix

    CC Newcomer

  • Member
  • PipPip
  • 11 posts
  • Programming Language:Java, PHP, PL/SQL
  • Learning:C#, JavaScript, Visual Basic .NET

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>
  • 0

#2 wim DC

wim DC

    Roar

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 2681 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Python

Posted 13 August 2012 - 10:18 PM

if (nation.checked= true)

You're not checking if it equals true. You set it to true there.

To check if it equals you need 2 or 3(more strict) equal signs.

Or in case of true/false:
if(nation.checked)

  • 0





Also tagged with one or more of these keywords: checkbox, div, hide, show, hide element, show element, hide div, show div, checkbox.checked

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download