J.Z. J.Z. - 2 years ago 197
Javascript Question

JQuery, get input id

$(document).ready(function() {
$('#hotelo_div :input').onblur = validate(1, this.id, "abcd");

<div id="hotelo_div">
<table id="hotcalcmain">
<td class="hotcc"><input type="text" id="PMI_1" maxlength="2" size="2" > %</td>
<td class="hotcc"><input type="text" id="PMI_2" maxlength="2" size="2"> %</td>
<td class="hotcc"><input type="text" id="PMI_3" maxlength="2" size="2"> %</td>
<td class="hotcc"><input type="text" id="PMI_4" maxlength="2" size="2"> %</td>

How to send input id(e.g. PMI_1, PMI_2, ...) to function validate for parameter at posiont "this.id"?

Answer Source

$('#hotelo_div :input').onblur should be assigned a function reference rather than the returned value of a function. Also this will not point to the input here. If you are using jquery, then you can use the jquery event handlers itself.

replace this line

$('#hotelo_div :input').onblur = validate(1, this.id, "abcd");


$('#hotelo_div :input').blur(function(){
  validate(1, this.id, "abcd");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download