How to disable and enable HTML form fields using JavaScript

To enable a form field use the below JavaScript document.getElementById("ELEMENT_ID").disabled = false; And to disable the form field use the below JavaScript document.getElementById("ELEMENT_ID").disabled = true; NOTE: Replace ELEMENT_ID with the form fields ID

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

How to encode a URL in JavaScript

There are two JavaScript function that you can use to accomplish this encodeURIComponent() Encodes a URI component Encodes special characters The following characters: , / ? : @ & = + $ # are encoded var url="http://test.com/index.php?url"+encodeURIComponent(url); encodeURI() Encode a URI Encodes special characters but not (except) , / ? : @ & = + $ # var url="http://test.com/index.php?url"+encodeURI(url);

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

How to find the height of you're webpage using JQuery

$(document).ready(function() { var height = $('body').height(); alert(height) }); NOTE: Remember to include the JQuery library file.

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

How to find the id of the first anchor html element within the first element of an unordered list using JQuery

With getting the id I mean getting the attribute id’s value for the first element within the first element of the unordered list tag. Answer: We can obtain this by using the :first Selector from JQuery. Read more about the selector here Example: HTML <ul class="custom_class"> <li><a href="test1.html" id="1" name="link1" /></li> <li><a href="test2.html" id="2" name="link2" /></li> <li><a href="test3.html" id="3" name="link3" /></li> <li><a href="test4.html" id="4" name="link4" /></li> <li><a href="test5.html" id="5" name="link5" /></li> </ul> JQuery ...

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

How to force a user to only enter numbers into a text field using JavaScript

Add the following JavaScript function to your HTML page function isNumberKey(evt) { var charCode = (evt.which) ? evt.which : event.keyCode if (charCode > 31 && (charCode < 48 || charCode > 57)) return false; return true; } The above function checks the input of the user and then returns false if no number has been entered and true if a number has been entered Then in your textfield HTML code add the following ...

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

How to get the current date using JavaScript

This can be obtained by using the Pre-defined object (Date) in JavaScript Example: document.write("The current date is:"+Date())

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

How to get the file extension from a filename using Javascript

var filename = 'myFile.jpg'; var ext = filename.split('.').pop(); //We split the filename on every instance where the . is found and then getting the last element in the array using the pop() function alert(ext);

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

How to get the full url using JavaScript?

Use the following code to obtain the full URL [code]var fullURL = window.location.href; alert(fullURL);[/code] location.href holds the current URL for reference purposes and can be changed at any time. Once changed the page will reload with the new assigned URL

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

How to get the id of the first html element within a div tag element using JQuery

How to get the id of the first img html tag element within a specific div tag using JQuery? With getting the id I mean getting the attribute id’s value for the first element within the div tag. Answer: We can obtain this by using the :first Selector from JQuery. Read more about the selector here Example: HTML <img id="1" name="image1" src="myImage1.jpg" width="200" border="1" /> <img id="2" name="image2" src="myImage2.jpg" width="200" border="1" /> <img id="5" name="image3" src="myImage3.jpg" width="200" border="1" /> </div> JQuery ...

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

How to get the size of a array using JavaScript

To get the total size of the array elements within an JavaScript array the JavaScriptlength property can be used. E.g. var arr = new Array(); arr[0] = 'val 1'; arr[1] = 'val 2'; alert(arr.length); //Will output 2

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