Showing posts with label javascript. Show all posts
Showing posts with label javascript. Show all posts

Sunday, February 03, 2008

Checkbox in APEX

You want to create a checkbox in Oracle Application Express and get it's value in javascript?

An example of a checkbox:
In my application I want to do an interactive search whenever the checkbox is checked.

So, how do you know if the checkbox is checked? Let's try with an example.

  1. Create a new "Check Box" item and give it a name, for ex. P26_CHECKBOX.
  2. In the List Of Values, put STATIC2: ;Y (this checkbox doesn't have a label, but will return the Y value whenever the checkbox is checked)
  3. If you look at the Session State (in the developer toolbar) of the item after a submit of the page, you see the checkbox item has a value of Y when it's checked...
  4. If you want to get the value of an item in javascript within APEX, you normally do $x('ITEM_NAME').value
  5. So let's try $x('P26_CHECKBOX').value -> it returns: undefined
  6. If you know a bit of javascript/html, you maybe think you need to use $x('P26_CHECKBOX').checked -> it returns: undefined
  7. The above doesn't work, because APEX is putting a number after the item. In my example: $x('P26_CHECKBOX_0')
  8. If you try with $x('P26_CHECKBOX_0').value, it return Y or with $x('P26_CHECKBOX_0').checked, it returns true... and that's what we'd like to have
  9. See it in action here
If you've more checkboxes (because the lov is returning more values) you can use following function to see what's checked: