How to check if a checkbox has been checked using JQuery

The following code checks if a checkbox has been checked var checkBox = $("input[name='myCheckBox']:checked").val(); if(checkBox == 'on'){ alert('CHECKED!!'); }else{ alert('NOT CHECKED'); } myCheckBox is the name of the checkbox element e.g. <input type="checkbox" name="myCheckBox" />

March 21, 2018 · 1 min · 35 words · icarnaghan

How to check if a value is a number or not a number using JavaScript

By using the isNaN() JavaScript function. isNaN = Is Not A Number Examples: document.write(isNaN(“Hello World!”)); //Will print true since Hello World! is not a number document.write(isNaN(123456)); //Will print false, since 123456 is a number. var phoneNumber = 0724956785234; if(isNaN(phoneNumber) == true){ alert(“Please enter a valid phone number”); return false; }

March 21, 2018 · 1 min · 50 words · icarnaghan

How to check if an html element exists with an specific ID using JQuery

This can be achieved by using .length if($("#id_name").length == 0) { //the element with id_name does not exists }

March 21, 2018 · 1 min · 19 words · icarnaghan

How to check if JQuery library is loaded

Use the following code withing your JavaScript tags if(jQuery){ alert('jQuery loaded'); }else{ alert('jQuery not loaded'); } This method can be used to check if any other JavaScript variable or function exists or is set and thus is not limited to jQuery alone.

March 21, 2018 · 1 min · 42 words · icarnaghan

How to clear all cache in Joomla 3.6.x?

Joomla 3.6.x includes effective caching options. Caching can help speed up your website and increase performance drastically. It also reduces load on your hosting server. To clear all the cache in Joomla 3.6.x you have to execute the following steps: Log into your Joomla Administrator dashboard In the top menu, click on **System->Clear Cache ** To clear all cache, click on the Delete All button All cache is now cleared in your Joomla 3.6.5 or higher installation ...

March 21, 2018 · 1 min · 77 words · icarnaghan

How to count the number of options in a select box using JQuery

This can be done using the jQuery length property You will use the following command to determine if there are any options within the select box. var length = $('#selectBoxId > option').length; console.log(length); #selectBoxId should be replaced with the ID of your select box.

March 21, 2018 · 1 min · 44 words · icarnaghan

How to count the number of table rows within an html table using JQuery

var countRows = $('#tableID tr').length; alert(countRows) or var countRows = $('#tableID tr').size; alert(countRows) The selector takes all rows and then counts them.

March 21, 2018 · 1 min · 22 words · icarnaghan

How to covert a string to lowercase using JavaScript

Use the string.toLowerCase() function as the example below <script type="text/javascript"> var str="I NEED THIS STRING TO BE CONVERTED TO LOWER CASE"; document.write(str.toLowerCase()); </script>

March 21, 2018 · 1 min · 23 words · icarnaghan

How to decode a JSON string using JavaScript

If you have a JSON encoded string that you might have received from a ajax scriptand you need to decode it using JavaScript you can use the eval() function to decode the string. The eval() function evaluates or executes an given argument. Example: var string = '{"id" : 32}'; var d = eval('(' + string + ')'); alert(d.id); //will alert 32

March 21, 2018 · 1 min · 61 words · icarnaghan

How to disable all html form elements within a DIV tag using JQuery

NOTE: Please not that the prop JQuery function should be used instead of the attr function in JQuery 1.6 and higher Answer: To disable all input elements within div use the following code: $(’#message :input’).attr(‘disabled’, true); To disable all select elements within div use the following code: $(’#message :select’).attr(‘disabled’, true); To disable all submit buttons within div use the following code: $("#message :submit").attr(“disabled”, “true”); Explanation: The DIV tags ID is message attr- Access a property on the first matched element. $(“selector”) If disabled is set to false the element won’t be disabled

March 21, 2018 · 1 min · 92 words · icarnaghan