tmss_it_dept
asked on
Validate Dynamic Checkbox (multiple values)
Hello all. I have an app that allows a user to apply multiple Courses and Required Reading to a new Qual. So, the user will type in the name of the new qual, and from a series of checkboxes (quantity varies), they will assign various reading and courses to this new qual. I need to be able to run though each checkbox and see if it has been checked, and if so, I need to enter the values in the database. The problem that I am having is that each checkbox will have 2 values, e.g. CourseNO and CourseDesc. These are two separate fields in the database for other reasons. So, how would I cycle through them and get these two values?
I am creating the checkboxes with the following code:
Would I just put the value of the checkbox to both variables separated by some special character and then just use some sort of Trim function to separate the variables and add them to the database?
Thanks,
Mike
I am creating the checkboxes with the following code:
<% While Not rsGetCourse.EOF %>
<tr>
<td align="right"> </td>
<td><label> <input type="checkbox" name="cbxReqCourse" id="cbxReqCourse" /> </label><%=rsGetCourse("dbCourseNo")%> - <%=rsGetCourse("dbCourse")%></td>
<td> </td>
</tr>
<%
x = x+1
rsGetCourse.MoveNext
Wend
%>
Would I just put the value of the checkbox to both variables separated by some special character and then just use some sort of Trim function to separate the variables and add them to the database?
Thanks,
Mike
>Sound feasible?
Yes, why not?
You may use hidden fields too.
Yes, why not?
You may use hidden fields too.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yeah, I was actually working on the first method (ID as checkbox value) now, so will let you know the results/problems. :)
Mike
Mike
ASKER
Ok, so I did get stuck. Being that I am using javascript to check certain fields are filled in before submitting, I am assuming that I need to create the Array() using javascript as well??? If so, how would I use this array to populate the database? OR, if I am using vbscript for the array, then how would I check the values of the the dynamic checkboxes?
Mike
Mike
You can do your validation in javascript before submitting the form. On the server-side everything with the same name is submitted as an array.
If you are looking to verify something in the checkboxes, like one of them must be selected. then you can do something like
if( $("input[name=cbxReqCourse ]:checked" ).length() > 0 ) {
// at least one checkbox was checked.
}
If you are looking to verify something in the checkboxes, like one of them must be selected. then you can do something like
if( $("input[name=cbxReqCourse
// at least one checkbox was checked.
}
ASKER
Ok, you say that everything on the server-side (same name) is submitted as an array, is that array called cbxReqCourse? As far as what I am trying to do is to find out which checkboxes have been checked, and then enter records in the database based on which ones are checked.
Thanks,
Mike
Thanks,
Mike
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That is a very good article. I will definately put it in my archives. I found a snippet similar to the one you mentioned earlier about using a hidden field and using a special character to separate values and then extract them later. Instead of using a hidden field though, it was just using a variable basically the same. I am then sending that variable in string to another page for processing.
Thanks for the ideas,
Mike
Thanks for the ideas,
Mike
ASKER
Mike