简体   繁体   中英

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?

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?

Ajax call in the handler + "handler not working aaaaaarghhhhh hellpppp" = usually means a not working Ajax call.

I am not sure what library you are using for your Ajax call, but try to add something like an onError callback function there where you are adding onComplete. I bet that will be called because there is a problem with the Ajax call.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM