Javascript: Creating a basic popup window


Javascript gives you the ability to open new windows in you’re browser. You’ll also have the ability to run any code in these windows, you could even have actions in the one window that will affect another window. The following statement is used to open up a basic popup window“popup.html”,”PopUp...

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
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;

How to encode a URL in JavaScript


There are two JavaScript function that you can use to accomplish this


Encodes a URI component
Encodes special characters
The following characters: , / ? : @ & = + $ # are encoded

var url=""+encodeURIComponent(url);


Encode a URI
Encodes special characters but not (except) , / ? : @ & = + $ #

var url=""+encodeURI(url);

How to set a timer in JavasScript


If we want to call a function every 10 seconds using JavaScript we can accomplish it by implementing the following piece of code window.setInterval('yourfunction()', 1000);   function yourfunction(){ alert('test');   } With the code above every 10 seconds a JavaScript function with the name yourfunction will be called that will prompt an alert. window.setInterval = Evaluates an expression each...

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...

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.

var string = '{"id" : 32}';
var d = eval('(' + string + ')');
alert(; //will alert 32

How to suppress JavaScript errors


Create a JavaScript function called suppressJS()

function suppressJS(){return true;}

Then within the head tags add the following code


Your complete code will look like this

<script type="text/javascript">
function suppressJS(){return true;}

About Author

Ian Carnaghan

I am a software developer and online educator who likes to keep up with all the latest in technology. I also manage cloud infrastructure, continuous monitoring, DevOps processes, security, and continuous integration and deployment.

Follow Me