Click to See Complete Forum and Search --> : Validating set of checkboxes & text boxes in loop


shanuragu
07-15-2003, 07:49 AM
Hi

Here is the Code used to display check box & text displyed using a loop

<%
Dim TitleId
While Not RsCdTitle.Eof
TitleId=RsCdTitle("CdTitleId")
%>
<tr>
<td class="border_1" colspan="2">
<input type="checkbox" name="cdtitle" tabindex='5' value='<%=RsCdTitle("CdTitleId")%>'>&nbsp;&nbsp;<font class="lilahometextcolor"><%=RsCdTitle("CdTitle")%></font>
</td>
<td class="border_1" colspan="2" align="center">
<input type="text" name="ucost<%=RsCdTitle ("CdTitleId")%>" value='' tabindex='6' size="10">
</td>
<%
RsCdTitle.MoveNext
if RsCdTitle.Eof Then
%>
<td colspan="2">&nbsp;</td>
<td colspan="2">&nbsp;</td>
<%
Else
%>
<td class="border_1" colspan="2">
<input type="checkbox" name="cdtitle<%=RsCdTitle("CdTitleId")%>" tabindex='7' value='<%=RsCdTitle("CdTitleId")%>'><font class="lilahometextcolor">&nbsp;&nbsp;<%=RsCdTitle("CdTitle")%></font>
</td>
<td class="border_1" colspan="2" align="center">
<input type="text" name="ucost<%=RsCdTitle("CdTitleId")%>" value='' size="10" tabindex='8' >
</td>
<%
End if
%>
</tr>
<%
if Not RsCdTitle.Eof Then RsCdTitle.MoveNext
Wend
%>

How can I validate these check boxes & text boxes.
If first check box is clicked then it is amust to enter values in the text box adjecent to it.
Please help.

ShaRa

olerag
07-15-2003, 09:13 AM
First tell me how many checkboxes (and corresponding text
fields) there are?? Are you keeping track in your "while" loop
how many you are dynamically creating? If so, I would think
you'd need to pass this integer to the JS function in order to
check each check/text scenario. Finally, I would give the check/text objects generic names and concatenate the current
assignment so you can check the individual items during the
JS evaluation.

Such as:
1. If, lets say, 5 check/text objects were created, the names can be check1..check5 and text1..text5.
2. You can place the quantity of object rows in a hidden
object in the form for reference in the JS function.
3. In the JS validation function, the specific objects can now
be referenced in a for loop to see if the appropriate checkbox
is checked AND the corresponding text field does indeed
contain a value. The validation process stops once the
max amount of "check/text" objects is reached.
4. The "kickoff" validation can be a button using the
"onClick" event.

shanuragu
07-16-2003, 01:03 AM
Thanks for ur help. It is working fine.

How can I put these values in to the db table.

Shara

olerag
07-16-2003, 10:05 AM
What values are you refering to? The one(s) in the textfield(s) objects?? Also, what exactly do you mean by "db table"?

shanuragu
07-16-2003, 12:50 PM
Both text box values as well as check box values should be put in to the db table by name cdprice.
Shara

olerag
07-16-2003, 03:03 PM
Not sure where we're going with this but...

1. Extraction of a value in a textfield (named "text1"):

var temp = document.forms[0].text1.value;

2. To see if a checkbox (named "check1") is checked:

if (document.forms[0].check1.checked)
alert("The checkbox is checked.");

Again, I don't know what you mean when you refer to "db table". Is this a form object, a table data cell, or are you talking about a database table??

Finally, your reference to "cdprice" is also unknown. In your original code, there was no such object with this name.

This originally began as a "validation" issue but I'm not sure what your last 2 questions refer to.

shanuragu
07-16-2003, 11:00 PM
Hi

CdPrice is a database table where in I have to insert all the values taken from the text box & check box.

I have one more problem.
One of the text box in the list (II text box in the list) always accompany with a , (comma). I only take values which are not empty , but along with this even this text box values comes as a ,. What could be the reason??.
Because of this I cannot validate this field. When ever I try to check validation with this field, since it takes comma (which is not visible, it will be dispalyed only when I response.write the value.) It will always be true.

Please help.

shara

olerag
07-18-2003, 08:04 AM
Sorry, I was at the hospital yesterday.

I'm only guessing here but when initially populating the textfields it may be that as your looping thru the cursor to retrieve values from the DB, you may be separating each value with a comma. Consequently, at the end of the retrieved string, your values might look something like,
"Value1,Value2,Value3,". A null return would then be represented only as ",". Regardless, this may be why the last value contains a comma.

If this is the case, the solution is to "right trim" the comma form the string once all of the values are fetched and before you transfer the information to your "sevlet's form?".

You can also perform most if not all string functions using Javascript if you prefer to handle unwanted string information during your validation. For info regarding substring functionality, check-out the Javascript "substring" and "replace" functions.