Search Your Question

Friday, July 24, 2009

Disable any element in a HTML page by JavaScript



document.getElementById('id').disabled=true;

Tuesday, July 21, 2009

JavaScript Text Field formatter for input money

function moneyonly(e)
{
    var unicode=e.charCode? e.charCode : e.keyCode;
    var st = document.getElementById("amount").value;
//alert(unicode)
    if (unicode== 8)
    {
        return true;
//if the key isn't the backspace key (which we should allow)
    }
    else if(unicode == 46)
    {

        if(st.toString().indexOf(".",0) != -1)
        {
            return false;
        }

    }
    else if (unicode<48||unicode>57) //if not a number
    {

        return false //disable key press
    }
    else if(st.toString().indexOf(".",0) != -1)
    {
        if(st.toString().length - st.toString().indexOf(".",0) > 2)
        {
            return false;
        }
    }

    return true;
}

Trim function in JavaScript

function trimThis(value1)
{
    value1= value1.replace(/^\s+|\s+$/, '');
    return value1;
}