hi there could any one solve this problem for me plzz.....

In my site iam generating multiple textfields and i need to wite validation for that

function valid(){

for(var i=0;i<4;i++){
if(document.getElementById('d'+i).value == ""){
alert("not empty");
return false;
return true;
<form name="f1">
<input name="cc1" id="d1" type="text" value="0" />
<input name="cc2" id="d2" type="text" value="0" />
<input name="cc3" id="d3" type="text" value="0" />
<input name="cc4" id="d4" type="text" value="0" />
<input name="submit" type="submit" onclick="return valid()" />

The following code is checking if the text boxes that are named "text" have values
and if thats correct the code returns true and submit the form, all it does is checking if one of the text boxes have values, but if u want all the text boxes to have values u have to validate each one of them.

// "Text" elements are textboxes

var validText = false;

for (var i = 0; i<document.MyForm.elements.length; i++) {
if (document.MyForm.elements[i].name = "Text" (
if (document.MyForm.elements[i].value != "") {
validText = true;

return validText;