This discussion is archived
5 Replies Latest reply: Feb 22, 2013 3:46 AM by MarkoGoricki RSS

Dynamic Actions Call a Javascript function on all text items

CJ Bell Newbie
Currently Being Moderated
APEX version 4.02

Hi

on a tabular form I have 50 columns each an input box , (basically 50 weeks of the year)

in these boxes I want to make them numbers only and max length 2

currently I have in the ELEMENT ATTRIBUTES for each column OnFocus="javascript:this.maxLength=2"; onKeyPress="return numbersonly(this,event)";
( I have a function called numbersonly in page 0 )

what I would like to do , to make it more maintainable is to remove all the calls in the element attributes of each column

and put it in 2 dynamic actions how would I go about this ?

I have tried using jquery selector of input:text to call javascript code on both events , Getfocus and KeyPress for every text box but its not working

thanks in advance

Chris
  • 1. Re: Dynamic Actions Call a Javascript function on all text items
    MarkoGoricki Journeyer
    Currently Being Moderated
    Hi Chris,

    try to use selector input[type="text"] or DOM Object input.

    Br,
    Marko Goricki
    --------------
    http://apexbyg.blogspot.com/
  • 2. Re: Dynamic Actions Call a Javascript function on all text items
    CJ Bell Newbie
    Currently Being Moderated
    Hi Marko thanks for the reply

    my selector of input:text is working fine as I use it for another dynamic action , it is my javascript in the code section that i'm stuck on

    for the length = 2 i put this.maxlength=2 but that doesn't work on a getfocus event

    and for the function I put the call which is - return numbersonly(this,event) on a keydown event

    thanks

    Chris
  • 3. Re: Dynamic Actions Call a Javascript function on all text items
    MarkoGoricki Journeyer
    Currently Being Moderated
    Hi Chris,

    Sorry, I've misunderstood you.

    For setting max length use onLoad DA, execute JS code:
    $('input[type="text"]').each(function(){
      $(this).attr('maxlength', '2');
    });
    To narrow selector put your region id in front of input[type="text"], e.g.
    $('#myRegionID input[type="text"]').each(function(){
      $(this).attr('maxlength', '2');
    });
    For referencing triggering element you can't use this object, it's this.triggeringElement. Also for event in keydown DA, you should use this.browserEvent.

    See help:
    Specify any custom JavaScript here that is specific to the page or dynamic action. This code has access to the following dynamic action related attributes:

    this.triggeringElement - A reference to the DOM object of the element that triggered the dynamic action.
    this.affectedElements - A jQuery object containing all the affected elements.
    this.action - The action object containing details such as the action name and additional attribute values.
    this.browserEvent - The event object of event that triggered the event. Note: On load this will be equal to 'load'.
    this.data - Optional additional data that can be passed from the event handler.

    Br,
    Marko Goricki
    -------------------
    http://apexbyg.blogspot.com/
  • 4. Re: Dynamic Actions Call a Javascript function on all text items
    CJ Bell Newbie
    Currently Being Moderated
    Marko

    Thats great , works brilliantly

    and for the other function I tried this but it didn't work :-((

    $('input[type="text"]').each(function(numbersonly(this,event););
  • 5. Re: Dynamic Actions Call a Javascript function on all text items
    MarkoGoricki Journeyer
    Currently Being Moderated
    Hi Chris,

    For the other one you should use on KeyPress DA and again not this and event but this.triggeringElement and this.browserEvent.

    Br,
    Marko Goricki
    ----------------------
    http://apexbyg.blogspot.com/

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points