开发者

Jquery :getting Object Expected Error when using the onchange() for textfield

i have a textfield like this

<input type = "text" name ="text1" id ="text1" onchange="displayresult()">


function displayresult(){
   alert("testing")
}

It is giving object expected error 开发者_如何学Pythonin IE6.o . when we debug in mozilla it is pointing to function name in this way

`function onchange(event) {
     displayresult(); //The cursor is pointed over here 
}`

How can i correct this


Going by your description and your example, I think your displayresult() function declaration is below the 'onchange' input text usage. The solution below uses the document.ready() event, and then uses the ID selector and .change() to register your 'onchange' needs. you can remove the onchange="displayresult();" in your html if you use my code below

<script>
function displayresult(){
   alert("testing");
}
$(document).ready(
    function(event){
     $("#text1").change(function(event){
       displayresult();
     });
});
</script>


If you are using jQuery - you should be able to just use selection via jQuery along with it's change() to help you out, that way you wouldn't need the displayresult() in your input declaration. This should help out out:

Example:

$(document).ready(function()
{
    $('#text1').change(function()
    {
        alert("testing");
    });
});

So that each time the text is changed in your textbox, you will be alerted.


You have not provided enough information to accurately determine why the error is occurring. I would guess that your function is not defined soon enough on the page. Also, you've tagged this question as jQuery related but in your code you are not referencing jQuery at all.

If you want to use jQuery Rionmonster is correct.

If you want to use javascript without jQuery, then you need to provide more information.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜