Jump to content

Cascade color through input fields


mwl707

Recommended Posts

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

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.