Friday, May 19, 2017

JavaScript notes

call JavaScript after page load

This can be used to hide some elements.
2 ways:

a) using JavaScript at the bottom of the page - just before </body>
after DOM is constructed

<script>
alert("page is loaded");
</script>


b) using jQuery - mostly placed in head section:

 <script>
        $(document).ready(function() {
alert("page is loaded");
});

</script>


Set visibility of items

Hide element based on selected item in dropdown list (<select>).

<script>
var optionList = document.getElementById('customerTypeSelection');
var customerTypeId = Number(optionList.options[optionList.selectedIndex].value.split(',', 1));
var acquirersRow = document.getElementById("Acquirers");
if (customerTypeId == 7) {
acquirersRow.style.display = '';
} else {
acquirersRow.style.display = 'none';
}
</script>




No comments:

Post a Comment