mwl707 Posted September 30, 2009 Share Posted September 30, 2009 I am trying to turn all the input fields in my form red BUT I want it to appear one line at a time . I have tried introducing a delay but the whole of my form turns red instantly. I have include my code , could anyone tell me what I am doing wrong please ?? (My HTML form is called form1) <script> function form_val() { var elem = document.getElementById('form1').elements; leg = elem.length for (i=1; i<leg; i++) { Vname = elem.name try { document.getElementById(Vname).style.backgroundColor='red' setTimeout("",1250); } catch(err) { } } return false ; } </script> Quote Link to comment Share on other sites More sharing options...
Psycho Posted October 1, 2009 Share Posted October 1, 2009 Tested in IE only <html> <head> <script type="text/javascript"> function colorFields(fieldIdx) { fieldIdx = (!fieldIdx) ? 0 : fieldIdx; var fields = document.getElementById('theForm').elements; fields[fieldIdx].style.backgroundColor='#ff0000'; fieldIdx++; if(fieldIdx<fields.length) { setTimeout('colorFields('+fieldIdx+')', 500); } return true; } window.onload=colorFields; </script> </head> <body> <form id="theForm"> <input type="text" name="field1" /><br /> <input type="text" name="field2"/><br /> <input type="text" name="field3" /><br /> <textarea></textarea><br /> <input type="checkbox"><br /> <input type="radio"><br /> <input type="radio"><br /> </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.