Flashing javascript textbox asp.net

kimjongil
kimjongil used Ask the Experts™
on
I have a page with textboxes created in the code behind based upon an imported dataset. The goal is to make the textbox back color flash if certain text is in the textbox.  The text I'm looking for will not be the only text there.  My approach was to apply a custom attribute when the textboxes are created to mark a textbox as having the text.  Then, I would use javascript to check the textboxes for this attribute and begin changing the backcolor on those textboxes with the attribute.  

Everything seems to work correctly if I manually write in the textbox name into the javascript.  The problem occurs when pulling the attribute and then changing the backcolor with variable identifies.  The only way it works is if I throw in an alert(), which makes me think something's not available for the code to proceed.  

I've attached a sample of the way the attributes are being added in vb as well as the javascript to change the back color.  Any suggestions would be greatly appreciated.  If this is NOT a good way to achieve the what I'm trying to, what would you recommend?  This must be able to work for any textbox on the page with the attribute.

Many thanks.
Private Sub CreateTextbox()
   newtextbox.Attributes.Add("test", "this")
End Sub

<script type="text/javascript">

    window.onload =

    function test() {

        var c = 0;
        var i
        var att 
        var nm
        var t
        for (i = 0; i < form1.elements.length; i++) {
           att = form1.elements[i].getAttribute("test")
           if (att == "this") {
               nm = form1.elements[i].name
               timedCount(c, nm);
               }
        }
    }

    function timedCount(c, m) {
        alert(m)
        if (c > 0) {
                document.getElementById(m).style.backgroundColor = 'RED';
                   c = 0;
               }
               else {
                   document.getElementById(m).style.backgroundColor = 'Yellow';
                   c = c + 1;
               }
               var t = setTimeout(timedCount(c, m), 500);
           }
</script>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2012
Top Expert 2014

Commented:
Where is the textbox? Inside another container?

Author

Commented:
Thanks for the response.  The series of textboxes are added directly to form1.  

form1.Controls.Add(newtextbox)

Author

Commented:
Issue resolved.

<script type="text/javascript">
          var c = 0;
          var t;
          var timer_is_on = 0;
          var att;
          
          window.onload = function() {
              if (!timer_is_on) {
                  timer_is_on = 1;
                  timedCount();
              }
          }

          function timedCount() {
              if (c > 0) {
                  for (var i = 0; i < form1.elements.length; i++) {
                      att = form1.elements[i].getAttribute("test")
                      if (att == "this") {
                          form1.elements[i].style.backgroundColor = 'Purple';
                      }
                  }
                  c = 0;
              }
              else {
                  for (var i = 0; i < form1.elements.length; i++) {
                      att = form1.elements[i].getAttribute("test")
                      if (att == "this") {
                          form1.elements[i].style.backgroundColor = 'Orange';
                      }
                  }
                  
                  c = c + 1
              }
              t = setTimeout("timedCount()", 100);
          }
        
      </script>

Open in new window

Author

Commented:
No suggestions received, found a solution that works on my own.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial