Form Validation

S

sanju

Dear All,

i have 10 textboxes on a form, I require the following validation

1) if i fill the textbox in between(say 5th), then all textboxes
before that should be mandatory,ie Textboxes(1,2,3,4) should be
mandatory and rest of the textboxes should not be mandatory.

Kindly help me out..

Thanks in advance..
Regards,
Sanjay
 
E

Erwin Moller

sanju schreef:
Dear All,

i have 10 textboxes on a form, I require the following validation

1) if i fill the textbox in between(say 5th), then all textboxes
before that should be mandatory,ie Textboxes(1,2,3,4) should be
mandatory and rest of the textboxes should not be mandatory.

Kindly help me out..

Well, what did you try so far?

You should make a validationroutine that checks excactly that.
What is the problem?
Don't you know how to get the content of a textarea?
Don't you know how to implement the logic to check the former X
textelements for emptiness?
Please state your problem clearer. :)

Erwin Moller
 
S

sanju

sanju schreef:





Well, what did you try so far?

You should make a validationroutine that checks excactly that.
What is the problem?
Don't you know how to get the content of a textarea?
Don't you know how to implement the logic to check the former X
textelements for emptiness?
Please state your problem clearer. :)

Erwin Moller






- Show quoted text -


Actually i dont know how to implement the logic to check the former
X..
Please help

Thanks,
sanjay
 
S

SAM

sanju a écrit :
Dear All,

i have 10 textboxes on a form, I require the following validation

1) if i fill the textbox in between(say 5th), then all textboxes
before that should be mandatory,ie Textboxes(1,2,3,4) should be
mandatory and rest of the textboxes should not be mandatory.


"should be" or "have to be" ?

Have to be :

function validate(myForm) {
var Cl = [];
for(var i=0, L=myForm.length; i++)
if(myForm.type= 'text') Cl[Cl.length] = myForm;
if(Cl.length==10 && Cl[4].value!='') {
for(var i=0; i<5; i++)
if(Cl.value == '') {
alert('textfield : '+Cl.name+\nis empty !');
Cl.focus();
return false;
}
for(var i=5; i<Cl.length; i++) Cl.value=='';
}
else {
for(var i=5; i<Cl.length; i++)
if(Cl.value == '') {
alert('textfield : '+Cl.name+\nis empty !');
Cl.focus();
return false;
}
for(var i=0; i<5; i++) Cl.value=='';
}
return true;
}

<form onsubmit="return validate(this);" blah >
 
S

sanju

sanju a écrit :
Dear All,
i have 10 textboxes on a form, I require the following validation
1) if i fill the textbox in between(say 5th), then all textboxes
before that should be mandatory,ie Textboxes(1,2,3,4) should be
mandatory and rest of the textboxes should not be mandatory.

"should be" or "have to be" ?

Have to be :

function validate(myForm) {
var Cl = [];
for(var i=0, L=myForm.length; i++)
   if(myForm.type= 'text') Cl[Cl.length] = myForm;
if(Cl.length==10 && Cl[4].value!='') {
    for(var i=0; i<5; i++)
      if(Cl.value == '') {
         alert('textfield : '+Cl.name+\nis empty !');
         Cl.focus();
         return false;
         }
    for(var i=5; i<Cl.length; i++) Cl.value=='';
    }
else {
    for(var i=5; i<Cl.length; i++)
      if(Cl.value == '') {
         alert('textfield : '+Cl.name+\nis empty !');
         Cl.focus();
         return false;
         }
    for(var i=0; i<5; i++) Cl.value=='';
    }
return true;

}

<form onsubmit="return validate(this);" blah >


Dear Sam,

Thanks a lot for the code..
You have written this code by assuming that i filled 5th text box, but
i want to fill any textbox between 1 to 10 and the textboxes before
the filled one have to be mandatory.

What shud i do?
Thanks in advance
 
S

SAM

sanju a écrit :
Dear Sam,

Thanks a lot for the code..
You have written this code by assuming that i filled 5th text box, but
i want to fill any textbox between 1 to 10 and the textboxes before
the filled one have to be mandatory.

I do understand nothing at all
- you told about the 5th
- madatory = filled
- which one before ? how much before ?
- what about next fields ?

function verif(form, what) {
for(var i=0; i<form.length; i++)
if(form == what && form[i-1].value == '') {
alert('You missed textfield : '+form[i-1].name);
form[i-1].focus();
form[i-1].select();
}
}

<input onkeyup="verif(this.form, this);" blah >
<input onkeyup="verif(this.form, this);" blah >
<input onkeyup="verif(this.form, this);" blah >
What shud i do?

don't use that it's not very hepful for visitor
 
J

Janwillem Borleffs

sanju schreef:
i have 10 textboxes on a form, I require the following validation

1) if i fill the textbox in between(say 5th), then all textboxes
before that should be mandatory,ie Textboxes(1,2,3,4) should be
mandatory and rest of the textboxes should not be mandatory.

This might help you:

<html>
<head>
<title> Form validation </title>
<script type="text/javascript">
function checkInputs(form) {
var inputs = document.getElementsByTagName('input');
var notempty = false;
for (i = inputs.length - 1; i > -1; i--) {
if (inputs.type == 'text') {
if (inputs.value.split(' ').join('')) {
inputs.style.borderColor = '';
notempty = true;
continue;
}
if (notempty) {
inputs.style.borderColor = 'red';
} else {
inputs.style.borderColor = '';
}
}
}
return false;
}
</script>
</head>

<body>
<form onsubmit="return checkInputs(this.form)">
<input type="text"/>
<input type="text"/>
<input type="text"/>
<input type="text"/>
<input type="text"/>
<input type="submit" value="submit"/>
</form>
</body>
</html>


JW
 
S

sanju

sanju a écrit :


Dear Sam,
Thanks a lot for the code..
You have written this code by assuming that i filled 5th text box, but
i want to fill any textbox between  1 to 10 and the textboxes before
the filled one have to be mandatory.

I do understand nothing at all
- you told about the 5th
- madatory = filled
- which one before ? how much before ?
- what about next fields ?

function verif(form, what) {
for(var i=0; i<form.length; i++)
if(form == what && form[i-1].value == '') {
   alert('You missed textfield : '+form[i-1].name);
   form[i-1].focus();
   form[i-1].select();
   }

}

<input onkeyup="verif(this.form, this);" blah >
<input onkeyup="verif(this.form, this);" blah >
<input onkeyup="verif(this.form, this);" blah >
What shud i do?

don't use that it's not very hepful for visitor



you r awesome Boss..
you have done it in just few lines of code..
hats off to u..
 
S

sanju

sanju schreef:
i have 10 textboxes on a form, I require the following validation
1) if i fill the textbox in between(say 5th), then all textboxes
before that should be mandatory,ie Textboxes(1,2,3,4) should be
mandatory and rest of the textboxes should not be mandatory.

This might help you:

<html>
<head>
        <title> Form validation </title>
<script type="text/javascript">
     function checkInputs(form) {
         var inputs = document.getElementsByTagName('input');
         var notempty = false;
         for (i = inputs.length - 1; i > -1; i--) {
             if (inputs.type == 'text') {
                 if (inputs.value.split(' ').join('')) {
                     inputs.style.borderColor ='';
                     notempty = true;
                     continue;
                 }
                 if (notempty) {
                     inputs.style.borderColor ='red';
                 } else {
                     inputs.style.borderColor ='';
                 }
             }
         }
         return false;
     }
</script>
</head>

<body>
<form onsubmit="return checkInputs(this.form)">
     <input type="text"/>
     <input type="text"/>
     <input type="text"/>
     <input type="text"/>
     <input type="text"/>
     <input type="submit" value="submit"/>
</form>
</body>
</html>

JW



This is also one of the good solution
Thanks boss

regards,
sanjay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top