Home » Archive

Articles in the Javascript Category

Javascript »

[13 Mar 2017 | Comments Off on Javascript: Populate Select box OnChange with JS array/object]

This article show how to populate one select box by selecting option of another select box/list. We will use a Javascript object. Each key of the object contains array as value.
A first select box is populated with the Javascript object’s keys. Then when the value from the first select box is selected then based on that value, the second select box is populated.

Javascript »

[15 Oct 2012 | One Comment]

This article shows how to get selected value from dropdown box when a button is clicked.
Problem:
– There are multiple forms in a page.
– There is a dropdown select box in each form.
– The option value of the select box is website URL.
– There is a button type=button (not type=submit) in each form.
– User will select a value from the select box and click the button.
– I need to get the selected option value (which is website URL) and open the URL in new window.

Javascript »

[2 Jan 2012 | Comments Off on Javascript: How to Submit form and Change form action?]

This article will show you how to submit form and change form action using javascript. This is a very simple trick but it’s very useful and frequently used.
Submit Form using Javascript

Javascript »

[26 Sep 2011 | Comments Off on Javascript: Show Hide textbox text on focus]

This might be simple one but it is a very handy code. Generally, I see this being used in Search textbox where there is some text like ‘search…’ by default. And, when you put the mouse cursor on the textbox, the text is removed and then you can type your desired search text.
For this, two javascript event handler are used: onFocus and onBlur.

Javascript, jQuery, Magento »

[2 Mar 2011 | 8 Comments]

By default, Magento contains and uses the Prototype javascript library. You can also integrate the other most popular javascript library ‘jQuery‘ in your Magento site.
While integrating jQuery in Magento, you might get some javascript conflict and errors as you will be using two javascript libraries (prototype and jQuery) at a time. This is caused because prototype also uses ‘$‘ as a function or variable name, just as jQuery does.

Javascript »

[28 Jan 2011 | 3 Comments]

Here is a quick code to get the current URL of a page with Javascript:-
var current_url = location.href;
Here is another way:-

Javascript »

[25 Jan 2010 | 3 Comments]

It is very easy to execute some code after a specified time-interval, i.e. setting some time interval between the code. We can use the setTimeout function.
Here is the code:

Javascript »

[8 Jan 2010 | 4 Comments]

It’s a real headache when you have to work on objects and arrays in Javascript. It would be lot easier to detect elements of the Javascript objects/arrays if we have print_r function in Javascript like we have in PHP.
I googled the web and have found a very efficient print_r Javascript function. Here is the code:-

Javascript »

[27 Nov 2009 | 2 Comments]

Here, I will be demonstrating on showing or hiding a div when a link is clicked. I have done this with Javascript and CSS.
I have called showHideDiv() Js function when the link is clicked. The display of the div where content is present, is visible or hidden on each click. For this, CSS styling is used (display: none).

Javascript »

[17 Nov 2009 | Comments Off on Javascript: Add Remove HTML elements]

You can add html elements dynamically with Javascript. In this article, I will show you how to do so. I have created two Javascript functions. One for creating html elements and the other for removing them.
In my html elements, I have created ‘li’ and ‘strong’ elements inside ‘div’. The div id is ‘summary’. I have written comment in the code so that it would be easy to understand.

Javascript, PHP »

[23 Oct 2009 | Comments Off on PHP Javascript : Playing with multi-dimensional array]

I had to work on multi-dimensional array with javascript and php. I had a multi-dimensional array in php. I had to load it into javascript array and then populate the html selection list.
The challenge for me was to create multi-dimensional array in javascript and populate selection list with for loop in javascript.