View Full Version : Help with a form.
lprais
06-25-2002, 04:51 PM
I am not very experienced with Java Script, I need to build a form, there is one area I am not sure how to do. I am hoping someone here has had a similar problem and over come it.
The portion I am trying to do consists of a array of 10 text boxes where the user is required to enter data into one of them.
Has anyone ever done something similar to this?
Thank you in advance
Lance
CODE:
see attached...
ecnarongi
06-25-2002, 05:13 PM
are you just looking to validate one of those form fields?? So you have ten but only one is required.
lprais
06-25-2002, 05:21 PM
Well out of ten one is required. Therefore, I need to validate as little as one but as many as 10 fields.
It needs to be dynamic.
Thanks
Lance
JohnKrutsch
06-25-2002, 05:36 PM
What is the validation criteria? YOu could just loop trhough the text boxes, check to see if they have stuff in them and if so validate them. Show us your code3 so far and tell us what the criteria for valifdation is.
lprais
06-25-2002, 05:54 PM
The criteria for validation is one of the text boxes is not Null. It is very simple, I just have never done anything other then validate one cell at a time.
For example I usually check boxes like so:
function CheckFields()
{
if (theForm.sr.value=="")
{
alert("Please enter the service request");
document.theForm. sr.focus();
return false;
}
if (theForm.web.value=="")
{
alert("Please if you found it form the web");
document.theForm. web.focus();
return false;
}
The problem with this is I do not care to check the other fields if at least one is checked.
Thanks
JohnKrutsch
06-25-2002, 06:09 PM
Show us the code for your form so we can see how it is set up.
landon11
06-25-2002, 06:25 PM
You could try something like this:
function CheckFields(){
var controls=document.theForm.elements;
var x = 10;
for (i=0;i<controls.length;i++){
if(controls[i].type=="text"){
if(controls[i].value==""){
x-=1;}}}
if(x==0){
alert("At least one text box must be filled.");
return false;}}
JohnKrutsch
06-25-2002, 06:32 PM
ladon11's will work as long as the text boxes in questions are the only text boxes in your form which is why I want to see the code for your form.
lprais
06-25-2002, 06:38 PM
I have attacehd the entire code along with the Javascript that I have already written.
THank you for your time
lprais
06-26-2002, 04:04 PM
does anyone have an idea on how to do this?
Thanks
Lance
JohnKrutsch
06-27-2002, 01:54 AM
Which of the text fileds from your form will be validated in this manner?
lprais
06-27-2002, 02:05 AM
The out of following fields at least one is required:
<tr>
<TD nowrap vAlign=top align=right width="30%"><font size="2" face="Arial, Helvetica, sans-serif"><b>Source</b></font><font face="Times New Roman, Times, serif" size="2" color="#990000">*</font></b></td>
</tr>
<tr>
<TD nowrap vAlign=top align=right width="30%"></td>
<td><font face="Arial" size="1">Service Request:</font> <input name="frmrequest" type=TEXT size='20%' value="" maxlength="20"></td>
</tr>
<tr>
<TD nowrap vAlign=top align=right width="30%"></td>
<td><font face="Arial" size="1">Web Site:</font> <input name="frmweb" type=TEXT size='20%' value="" maxlength="20"></td>
</tr>
<tr>
<TD nowrap vAlign=top align=right width="30%"></td>
<td><font face="Arial" size="1">Book/Manual:</font> <input name="frmbook" type=TEXT size='20%' value="" maxlength="20"></td>
</tr>
<tr>
<TD nowrap vAlign=top align=right width="30%"></td>
<td><font face="Arial" size="1">White Paper:</font> <input name="frmpaper" type=TEXT size='20%' value="" maxlength="20"></td>
</tr>
<tr>
<TD nowrap vAlign=top align=right width="30%"></td>
<td><font face="Arial" size="1">Other:</font> <input name="frmother" type=TEXT size='20%' value="" maxlength="20"></td>
</tr>
Thanks in advance for your help
Lance
adios
06-27-2002, 02:46 AM
I'm not sure I get this, but, anyway...
<script type="text/javascript" language="javascript">
function checkfields(f) {
var currEl, e = 0;
while (currEl = f.elements[e++])
if (currEl.oneRequired && currEl.value) return true;
alert('Something...');
return false;
}
</script>
HTML:
<form method="post" name="theForm" action="javascript:alert('Submitted !')"
onsubmit="frmrequest.oneRequired=true;frmweb.oneRequired=true;
frmbook.oneRequired=true;frmpaper.oneRequired=true;
frmother.oneRequired=true;return checkfields(this)">
Just add the .oneRequired property (=true) for every field you want included in the group. The alerts can be customized, but it's hard to do so without some idea of the methodology behind all this. hth
lprais
06-27-2002, 05:31 AM
I wanted to thank eveyone who helped me out with this problem.
Lance
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.