Avatar of kimjongil
 asked on

Flashing javascript textbox asp.net

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) {
        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);

Open in new window

JavaScriptASPVisual Basic.NET

Avatar of undefined
Last Comment

8/22/2022 - Mon
Nasir Razzaq

Where is the textbox? Inside another container?

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


Issue resolved.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

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