Friday 15 August 2014

How to appy one javascript function to multiple textbox onfocus event in asp.net -


I have two JavaScript functions that change the background color and skip the events.

  function ColoronEnter () {var txt1 = document.getElementById ("& lt;% = txtID1.ClientID%>"); Txt1.style.backgroundColor = "red"; } ColoronLeave () {var txt2 = document.getElementById ("& lt;% = txtID1.ClientID%>"); Txt2.style.backgroundColor = ""; }   

I will

  & lt; Asp: textbox id = "txtID1" runat = "server" maxlength = "20" autocomplete = "first name" onfocus = "coloroncenter" onblur = "color lev ()" & gt; & Lt; / Asp: text box & gt;   

This is working well but I want to implement a javascript function in all my text boxes. I have tried

  to the function (_input) {var input = _input; Document.getElementById (input) .style.backgroundColor = "yellow"; } (_input) on the function {var input = _input; Document.getElementById (input) .style.backgroundColor = ""; }   

is trying to call them

  & asp: textbox id = "txtID2" runat = "server" onfocus = "onEnter (txtID2) ) "OnBlur =" onLeave (txtID2) "& gt; & Lt; / ASP: text box & gt; & Lt; ASP: text box id = "TCTID3" run = "server" onfocus = "onEnter (txtID3)" onblur = "onLeave (txtID3)" & gt; & Lt; / Asp: text box & gt;   

This is throwing the error as a Microsoft JScript Runtime error: Unable to fetch the value 'properties': Object is blank or undefined.

How can I call a function in all my text boxes thanks in advance.

Use

    

If you have no restrictions to use jQuery, then use the event to handle it.

No comments:

Post a Comment