Search code examples
javascriptonkeyup

Javascript onkeyup function not working


Don't know whats exactly going on, but it's definitely killing my time for nothing. Here's my javascript function :

<script type="text/javascript"  >

function loadSponsorName() {
    var sp_id = document.getElementById('sponsor_id').value;
    var murl = 'load_sponsor.php?sp_id='+sp_id+'';

    var a=new Ajax(murl,{
        method:"post",
        onComplete: function(response){
        $('sponsorName').setHTML(response); 
        }
    }).request();
}
</script>

and inside a form this are my inputs

<tr>
    <td width="33%" height="20">
        <label id="namemsg" for="name">Sponsor ID:</label>
    </td>                          
    <td width="67%">
        <input type="text" name="sponsor_id" id="sponsor_id" size="40" value="" class="inputbox required" maxlength="50" onkeyup="loadSponsorName();" /> *
    </td>
</tr>
<tr>
    <td height="20">
        <label id="namemsg" for="name">Sponsor Name:</label>
    </td>                          
    <td><div id="sponsorName">
        <input type="text" name="sponsor_name" id="sponsor_name" size="40" value="" class="inputbox required" maxlength="50" /> *
    </div></td>
</tr>

It seems the onkeyup event is not even calling the function.

Can somebody help me?


Solution

  • onkeyup is working try this javascript code to see how works;

    function loadSponsorName() {
           alert(document.getElementById('sponsor_id').value);
    }
    

    I think there is a problem with;

     var a=new Ajax(murl,{
                method:"post",
                onComplete: function(response){
                $('sponsorName').setHTML(response); 
                }
            }).request();
    

    Where is Ajax class? Did you import it from an other lib?