Link to home
Start Free TrialLog in
Avatar of kimjongil

asked on

Flashing javascript textbox

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

Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Where is the textbox? Inside another container?
Avatar of kimjongil


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

Issue resolved.
Avatar of kimjongil

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
No suggestions received, found a solution that works on my own.