newhck / php-form-builder-class

Automatically exported from code.google.com/p/php-form-builder-class
GNU General Public License v3.0
0 stars 0 forks source link

How to capture event object? #150

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
I am trying to capture the 'onkeypress' event and then determine what key was 
pressed.

Using following code snippet...

$form->addElement(new PFBC\Element\Textbox("Location", "Location",
    array(
            "onkeypress" => "myJSFunction(this)";")
    ));

I am capturing the event, but cannot figure out how to get the event object so 
that I can find out what key was pressed.  JQuery says event.keycode() or 
event.which(), so if I can get the event I think I will be good to go.

It seems what I need to be able to do is pass the event to my JS Function.

Is there someway in PFBC to get the event?

What is the expected output? What do you see instead?

What version of the product are you using? On what operating system?
    Version: 2.1
    Released: May 15, 2011
Windows 7 using uWamp
PHP 5.3.5

Please provide any additional information below.

Original issue reported on code.google.com by plann...@ministryjobs.com on 6 Aug 2011 at 5:42

GoogleCodeExporter commented 8 years ago
I could not figure out how to capture the event, but it turned out to be easy 
to just use JQuery.
I gave the element an "id".

    $form->addElement(new PFBC\Element\Textbox("Location", "Location",
    array(
            "id" => "LocationTextBox")
    ));

Then used jquery to capture the event for this specific element in the form and 
do what I needed to do.

        $("#LocationTextBox").keypress(function(event) {
            alert("Key Was Pressed);
        });

Original comment by jb13bobi...@gmail.com on 24 Aug 2011 at 2:32