troubleshooting Question

Flashing javascript textbox asp.net

Avatar of kimjongil
kimjongil asked on
JavaScriptASPVisual Basic.NET
5 Comments1 Solution341 ViewsLast Modified:
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>
ASKER CERTIFIED SOLUTION
kimjongil

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros