Abijeet Patro
Abijeet Patro

Reputation: 2884

Unable to clear a TextBox using javascript

I'm unable to clear the text box when I hit the button with value C.

In Opera when I press the number buttons it properly inputs them into the text box but for some reason the C button never works! Here is the jsfiddle.

Thanks.


Edit: I haven't implemented all the functionality yet! Only the number buttons work.

Upvotes: 2

Views: 277

Answers (3)

Fabrício Matté
Fabrício Matté

Reputation: 70199

Rename your function to something else and it will work.

Fiddle

Now why clear was giving a conflict is beyond me, console.loging it returns undefined and it's not a keyword AFAIK.

edit: Check Zeta's comment, thanks for the info! clear is a deprecated function. Reference

Avoid such generic names in the future to skip some headaches. =]

Upvotes: 2

vivek salve
vivek salve

Reputation: 991

    function findKeyPressed(e)
{
var codeChar=e.keyCode? e.keyCode : e.charCode
    if(codeChar==67)
    {
        document.getElementById('txtBoxId').value="";
    }
}
   <input type="text" onkeyup="findKeyPressed(event); this.select()" />

Upvotes: 1

index
index

Reputation: 3727

Don't use clear. Function clear() is a reserve word I think

http://www.roseindia.net/javascript/javascript-clear-method.shtml

Upvotes: 1

Related Questions