1

I want to pass the texttbox id to javascript function and change the color of the textbox if the value is null.

function fnOnUpdateValidatorsNewChangeChange(txtid) {
    var txt1 = document.getElementById(txtid);
    var Value = document.getElementById(txtid).value
    if (Value == "") {
        txt1.style.background = "#FFF000";
    }
}


<asp:TextBox runat="server" ID="txtlabelID" class="textbox" TextMode="SingleLine" 
onchange="fnOnUpdateValidatorsNewChangeChange('<%= txtlabelID.ClientID %>')"

But it's getting Null error.

1
  • 2
    Your code seems to be working fine just terminate the statement by semi colon. var Value = document.getElementById(txtid).value; Commented Apr 20, 2015 at 10:06

1 Answer 1

1

you not need to pass ID of textbox and find textbox using the same id ..

You just pass this as a textbox in argument for E.g.

<asp:TextBox runat="server" ID="txtlabelID" class="textbox" TextMode="SingleLine" 
onchange="fnOnUpdateValidatorsNewChangeChange(this)"





 function fnOnUpdateValidatorsNewChangeChange(txtbox) {
    if (txtbox.value == "") {
        txtbox.style.background = "#FFF000";
    }
    else
        txtbox.style.background = "";
}

Is it more Simple ??

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.