views:

54

answers:

2

Hello folks,

I've got the issue to add a browser event to some input fields. The challenge I have to face is, that one parameter of my target function is the 'event'-variable and the second one an object.

For a better understanding here some codes:
The HTML object:

<div id="1_dateFieldAdvanced" class="xp set">
    <div id="1_dateFieldAdvanced_label" class="label">Birthday</div>
    <div id="1_dateFieldAdvanced_value" class="value date">
        <input class="day" name="dayOfBirth" value="66" maxlength="2" type="text">
        <input class="month" name="monthOfBirth" value="67" maxlength="2" type="text">
    <input class="year" name="yearOfBirth" value="" maxlength="4" type="text">
    </div>
</div>

The source code of target method is like below:

function advancedDateFields(currentFieldAsObject, nextField, currentValueLength, ev){}

Unfortunatly the HTML and the Javascript code is generated automatically, so I'm unable to refactore the code. My question is, how can I pass the key word 'event' and the other parameters? My tries did always fail. :-(

A: 

Hi, YOu can call function onkeypress: Example:

function(event) { customMethod(event, obj); }

I hope this helps..

TriLLi
Hello and thanks for your answer.I had tried this way too, but the Firefoxbrowser does not pass the event variable and the Internet Explorer does not the obj variable. That's why I asked you.
reporter
ok let me explain youadd to your input box onkeyup event and add like this<pre> testMethod(event, this);</pre>event is onkeyup event, and this is reference to object, all you need now is to create "testMethod"<pre>function testMethod(e, obj){ //your code here}
TriLLi
and by the way I have tried this in ie6 and firefox.. it's working
TriLLi
A: 

What about

$("input:text","#dateFieldAdvanced_value").bind("keyup", function(e){
    var currentElem = $(this);
    var currentValLength = currentElem.val().length;
});

I am not sure what you meant by next field.

Also you ids are invalid. Id should not start with a number. So I changed 1_dateFieldAdvanced_value to dateFieldAdvanced_value

rahul
Hello thanks for your answer. If you look at html, code you can see three input fields. The goal of mine is to add the keyup event to each input field. The parameter 'nextField' represents the name of next input field within current set.
reporter
Got it. And with method 'next()' I finished this issue.
reporter