Previous
Previous
 
Next
Next

Referencing Items Using JavaScript

When you reference an item, the best approach is to reference by ID. If you view the HTML source of an Oracle Application Express page in a Web browser, you would notice that all items have an id attribute. This id corresponds to the name of the item, not the item label. For example, if you create an item with the name P1_FIRST_NAME and a label of First Name, the ID will be P1_FIRST_NAME.

You can get and set item attributes and values using the JavaScript function $v('P1_FIRST_NAME'). Consider the following example:

  function firstName(){    
  alert('First Name is ' +$v('P1_FIRST_NAME'));
  }
 // or a more generic version would be
function displayValue(pId){   
  alert('The Value is ' + $v(pId));
  }
 
  // Then add the following to the "Form Element Attributes" Attribute of the item:
  onchange="displayValue('P1_FIRST_NAME');"