J.Z.
J.Z.

Reputation: 351

JQuery, get input id

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

<div id="hotelo_div">
    <table id="hotcalcmain">
        <tr>
            <td>PMI1</td>
            <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>
        </tr>
        ...

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

Upvotes: 2

Views: 109

Answers (4)

shivanand s gaddi
shivanand s gaddi

Reputation: 38

This code will pass the id of all the input tag within the 'hotelo_div' id of the particular div when text inside the textbox will change to the 'validate' method.

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

Upvotes: 1

Shubham Khatri
Shubham Khatri

Reputation: 281606

You can use the onblur event as follows. On a blur event you need to assign a function and not a returned value:

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

Upvotes: 1

Ibrahim Khan
Ibrahim Khan

Reputation: 20740

You should use blur event like following.

$('#hotelo_div :input').blur(function(){
    validate(1, this.id, "abcd");
});

Upvotes: 1

gurvinder372
gurvinder372

Reputation: 68363

$('#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");

with

$('#hotelo_div :input').blur(function(){
  validate(1, this.id, "abcd");
}) 

Upvotes: 1

Related Questions