Domanda

I am trying to check if a check box is checked and show an element on the page if it is checked.

This is my function:

function checkedTechSolutions(){    
    Y.one('#techsol input[type=checkbox]').on('change', function (e) {
        var target = e.currentTarget,
        techSBox = Y.one('#techsolutions');
        if (target.get('checked')){ 
            techSBox.show();
        } else techSBox.hide();
    }
}

This is my css:

#techsolutions {width: 380px; height: 100px; background-color:#cee4f2; display: none;}
#techsolutions .box {text-align: center;} 

This is my html:

<div id="techsolutions">

    <div class=box>
    <label for="TypeOfTS">Tech Solutions: </label>
    <select name="techSolutionsDrop">
        <option value="techServices">Choose your services </option>
    </select>
    </div>  

</div>
È stato utile?

Soluzione

Some notes:

  • Your example lacked the checkbox in #techsol
  • Was checkedTechSolutions ever called? You do not need a document ready type event to attach a listener to a checkbox when using YUI.
  • Use css classes to change visuals like this. It is easier to understand and cleaner.

Take a look at the full solution in this jsfiddle

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top