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> Link to comment https://forums.phpfreaks.com/topic/176079-cascade-color-through-input-fields/ 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> Link to comment https://forums.phpfreaks.com/topic/176079-cascade-color-through-input-fields/#findComment-928239 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.