Adding an keyUp-event to form objects
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">
开发者_C百科 <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. :-(
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
YOu can call function onkeypress: Example:
function(event) { customMethod(event, obj); }
I hope this helps..
function lookup(inputString) {
if(inputString.length == 0) {
// Hide the suggestion box.
$('#suggestions').hide();
} else {
// Show the suggestion box.
$('#suggestions').show();
}
精彩评论