JavaScript Tips & Tutorials

How to include a JavaScript file inside a JavaScript file?

This is a pretty odd question to ask in the first place if you have been using JavaScript for a while. JavaScript files are called from HTML web pages who need them to manipulate the HTML elements so that the users have extraordinary interactive experience. You can’t include a JavaScript file inside another JavaScript file …

How to include a JavaScript file inside a JavaScript file? Read More »

PHP and JavaScript Variable / Value Transfer / Exchange: How to pass variable values from PHP to JavaScript or JavaScript to PHP?

This is a rather common problem for novice web developers. While it may seem at first glance that it’s easy for PHP and JavaScript to communicate with each other, but they actually cannot interact with each other directly. They are very different technologies built for distinct purposes. How to transfer or pass variable values from …

PHP and JavaScript Variable / Value Transfer / Exchange: How to pass variable values from PHP to JavaScript or JavaScript to PHP? Read More »

How to execute / run PHP code inside JavaScript files?

Static files of JavaScript would survive most applications but sometimes the ability to include PHP code inside JavaScript scripts and generate the content of the script files on the fly by PHP is a better option. How does one do that? The simplest solution is to just include PHP code inside the <script></script> section of …

How to execute / run PHP code inside JavaScript files? Read More »

JavaScript: Confirmation / Warning before Leaving or Navigating Away from a Page

Things couldn’t be worse when you were half way editing something and accidentally navigated away from the editing page after a whole hour of typing work. Hitting the back button of your browser neither helped, all you had done was gone anyway. This must be remedied in some way, if you are creating an application …

JavaScript: Confirmation / Warning before Leaving or Navigating Away from a Page Read More »

How to define multiple CSS rules / properties in jQuery?

The simplest way to define a CSS rule in jQuery might be: $(".sth").css("color", "#f00"); To define more than one CSS rule in a single jQuery line: $(".sth").css("color", "#f00").css("font-style", "italic").css("text-decoration", "underline"); Which simply doesn’t look that good, especially if you intend to add more. A better way to specify multiple CSS rules or properties with jQuery …

How to define multiple CSS rules / properties in jQuery? Read More »

How to redirect the visitor to another page or website?

This is one of the most common tasks in website development and also one of the most frequently asked question according to some of the keyword research tools. Well, you have 3 ways to achieve a web page redirection. Use PHP header() function to modify and send a HTTP Location header: header("Location: /thankyou.html"); // redirect …

How to redirect the visitor to another page or website? Read More »

PHP, JavaScript: Stop and prevent others from framing your site or web page

Though it does increase traffic and the pageviews, it doesn’t feel quite good with someone who’s loading your website or page as a part of theirs in the form of a <frame> or <iframe>, leeching your content as part of theirs. To prevent them from loading your pages this way, and make the visitor browser …

PHP, JavaScript: Stop and prevent others from framing your site or web page Read More »

How to change the browser window status bar text of Firefox with JavaScript?

It’s strange that you can accomplish this in IE while you can’t make it happen in Firefox. Well, that’s because the development team has decided that it’s potentially annoying and harmful for web developers to change the text of Firefox status bar whatever way they want. So the simple answer is, you can’t. But there’s …

How to change the browser window status bar text of Firefox with JavaScript? Read More »

Best JavaScript Books for Learning JavaScript Programming and Development

Thanks to the computer scientists who set the standards of JavaScript, in the arena of event programming and behavioral manipulations of windows and objects, it is the one programming script that is so powerful that you can virtually build any possible interactive applications with it. That said, learning JavaScript to the mastery of it takes …

Best JavaScript Books for Learning JavaScript Programming and Development Read More »

JavaScript: Open or Redirect to Another Page / Site / Location

One of the most common uses of JavaScript is to redirect the user to or automatically open up another web page location. For example, when the user clicks a button, the JavaScript will redirect the user to the location selected in the drop down select menu. It’s just like the user has typed the web …

JavaScript: Open or Redirect to Another Page / Site / Location Read More »

JavaScript: Split and Divide Text String by A Delimiter

Spliting and dividing a string into several chunks is a rather basic need for text parsing. You can do it easily in PHP by the help of explode() function or preg_split(), in JavaScript, you can achieve this task by the split() string function. The following example illustrates the usage of javascript split() function to slice …

JavaScript: Split and Divide Text String by A Delimiter Read More »

jQuery: Protecting or hiding variables / functions in a specific local scope

As everyone who’s well trained in software engineering would agree, that one of the principle of writing predictable code is to separate and hide something within only the scope that it’s needed. Controlled access to and from the outside world brings predictability and accountability of your code thus better debugging. In jQuery, you need constantly …

jQuery: Protecting or hiding variables / functions in a specific local scope Read More »

jQuery: Get the text and value of the selected option of HTML select element

For instance, there’s a HTML select element identified by the ID #title, and after the user has selected one of the options, you want to get the text and value of the selected option. <select id="title"> <option value="1">Mr</option> <option value="2">Mrs</option> <option value="3">Miss</option> </select> Now that the user has selected the 2nd option: Mrs. To get …

jQuery: Get the text and value of the selected option of HTML select element Read More »

jQuery: How to check if an element has a particular class

To know whether a class exists on an element with jQuery, you need a simple test method: is(). For example, to test if an element #elm has the class ‘first’: if ($(#elm).is(‘.first’)) { //#elm has the class } else { //#elm doesn’t have the class } jQuery is() is the function that checks if any …

jQuery: How to check if an element has a particular class Read More »

jQuery: How to test or check whether an element exists

.length property in JavaScript returns the length or number of elements inside an array or the string length. While jQuery selector mechanism $(“elm”) returns an array of DOM objects (such as elements), you can also get the number of the length of the returned objects array by: $("#some").length To check the existence of the element, …

jQuery: How to test or check whether an element exists Read More »

jQuery: Selecting elements with uncommon / special characters in ID or class name

HTML generated by some CMS or frameworks include elements with rather uncommon characters in ID or class names. For example, some may have special characters such as ‘.’ or ‘[..]’ in the ID or Class. To work around this, a selector in jQuery should be written this way: $(“$some.id”) // won’t work for ID: some.id …

jQuery: Selecting elements with uncommon / special characters in ID or class name Read More »

Scroll to Top