recalculate fields and reinsert record based on checkbox values


I have a form with lots of numeric value fields. If the users want a similar record with a slightly different calculation on those values I was going to give them a whole separate form on a whole separate page to use, but I thought, what if the user could click a checkbox to say "Create a record with 1/3 these values" and another checkbox "Create a record with 1/4 these values" and so on. If the user checks one or more of these recalculate boxes, then upon Submit, the form would submit three records: one with original values, one with 1/3 values for all the identifed fields (not the name field for example), and one with 1/4 values, etc.

How hard is it to insert several records into the same table with 1 button click? And assuming I had a checkbox named onethird

if (onethird) = checked
(formfield1, formfield2, formfield4) * .33

Or something like that?

What would the syntax be in vbscript?

Any suggestions here?

Thank you
Who is Participating?
TheGDConnect With a Mentor Commented:
Create the two files CheckBox.asp and CheckBoxSubmit.asp as follows. It would demonstrate how you can calculate and reinsert records based on check box values while having a single form.



<form action="CheckBoxSubmit.asp" method=POST>

<input type=checkbox name="ChkOneThird" id="ChkOneThird" value="1">
<Label for="ChkOneThird"> One Third </Label>

<input type=checkbox name="ChkOneFourth" id="ChkOneFourth" value="1">
<Label for="ChkOneFourth"> One Fourth </Label>


Value 1: <input type=text name="Value1"> <br>
Value 2: <input type=text name="Value2"> <br>
Value 3: <input type=text name="Value3"> <br>

<input type="Submit" value="Submit">





Response.Write "Value1: " & Request.Form("Value1") & "<br>"
Response.Write "Value2: " & Request.Form("Value2") & "<br>"
Response.Write "Value3: " & Request.Form("Value3") & "<br>"

Response.Write "<br>"

Response.Write "Calculate OneThird For Each: " 
if Request.Form("ChkOneThird") <> "" then
      Response.Write "YES" & "<br>"
      Response.Write "Value1: " & Request.Form("Value1")/3 & "<br>"
      Response.Write "Value2: " & Request.Form("Value2")/3 & "<br>"
      Response.Write "Value3: " & Request.Form("Value3")/3 & "<br>"
      Response.Write "NO" & "<br>"
end if

Response.Write "<br>"

Response.Write "Calculate OneFourth For Each: " 
if Request.Form("ChkOneFourth") <> "" then
      Response.Write "YES" & "<br>"
      Response.Write "Value1: " & Request.Form("Value1")/4 & "<br>"
      Response.Write "Value2: " & Request.Form("Value2")/4 & "<br>"
      Response.Write "Value3: " & Request.Form("Value3")/4 & "<br>"
      Response.Write "NO" & "<br>"
end if


Michel PlungjanConnect With a Mentor IT ExpertCommented:

If you want the simple version:
function calc(theForm) {
 var val = parseInt(theForm.formfield1.value,10)+
<input type="hidden" name="totalThird">
<input type="hidden" name="totalFourth">
Or just do the calculation on the server if the user is not to see it anyway

Open in new window

It is very simple to handle such situation. You would have only 1 form and check boxes on the top saying Create a record with 1/3 these values" and another checkbox "Create a record with 1/4 these values" and vice versa.

Then upon submission of the form, the server side script would process the form values multiple times to insert them into database.

If you can tell me what server side script you are using like asp, php,, perl etc. then I can give you the sample code in the specific server side script.
billium99Author Commented:

It's ASPVB. It can't be transparent to the user because it is only to happen if the user elects to do so. So the OneThirdYesNo checkbox being checked triggers this second submittal (or third or fourth)


billium99Author Commented:
Thanks guys!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.