Blog

How to hide/show an HTML form element depending on a combo box choice

This is an example of how you can show/hide an HTML form element depending on a combo box choice.

Put the following JavaScript code between your <head></head> section (or within a .js file if you prefer).

  
<script language="javascript" type="text/javascript">
  function hide() {
    var text = document.formName.textBox;
    if(document.formName.combo.value == "hide") {
      text.style.visibility = "hidden";
    }
    else {
      text.style.visibility = "visible";
    }
  }
</script>

The following snippet of code instead is the HTML code to use to call the hide function.

Read more...

POJO (Plain Old Java Object): The simpler...the better.

A POJO is simply an object built using a Java class that does not implement any special interfaces such as those defined by the EJB 2 framework. An example of a POJO is a class composed by only:

  1. Properties, representing the object’s state.
  2. Getter and setter methods for the properties.
  3. Business methods, representing behaviour.

Some properties can represent associations with other POJOs. Here is an example of implementation of the Person entity using a POJO:

Read more...

Calling a function of the opener window

It is possible, using JavaScript, to call a function pertaining to the opener window, that is the window that, calling window.open, opened the current window. The code to use is the following:

  
if (window.opener) {
  window.close();
  window.opener.foo("bar");
}

First it checks if the opener window is still open. In this case, it closes the current window and call the foo function on the opener window.

Read more...

Creating a Class definition in JavaScript

There are different ways to define classes in JavaScript. However, this is the most widely used and accepted at the moment:

   
//class
function Person(sLastName, sFirstName, iAge) {
  this.lastName = sLastName;
  this.firstName = sFirstName;
  this.age = iAge;
  this.phoneNumbers = new Array();
}

//method
Person.prototype.showFullName = function() {
  alert(this.lastName + " " + this.firstName);
};

//instances
var oPerson1 = new Person("Lacava", "Alessandro", 30);
var oPerson2 = new Person("Brown", "John", 50);
oPerson1.phoneNumbers.push("1234567");
oPerson2.phoneNumbers.push("7654321");

oPerson1.showFullName(); //outputs Lacava Alessandro
alert(oPerson1.phoneNumbers); //outputs 1234567
oPerson2.showFullName(); //outputs Brown John
alert(oPerson2.phoneNumbers); //outputs 7654321
Read more...