Showing posts with label javascript. Show all posts

Number restriction in textbox using javascript  

Posted by Kishore in

I have a developed this simple javascript to allow user to key in only numerics and dot(for decimals).

function verify(e)
{
var zero=48;
var nine=57;
var dot=46;
if((e.keyCode==dot)||(e.keyCode>=zero && e.keyCode<=nine)){
return true;
}
return false;
}

Javascript scroll to top of the page  

Posted by Kishore in

If you are in the bottom of the html page and if you want to go to the top of the page, You can use the following java script.

window.scrollBy(-document.body.clientWidth,-document.body.clientHeight);

Otherwise if you wanna goto top... yes you are right, remove the minuses.

If you want to scroll inside any dom elements, you can use this javascript method to determine the height or width of that element.

document.documentElement.­clientHeight/Width

Alternative way to disable the select box  

Posted by Kishore in ,

In some browsers, disabling select box in HTML is not allowed.
So we can alternatively write the following on the select box.

It may need to be finetuned a bit to accommodate to double clicks.

onfocus="this.blur()"