Solved

# recalculate fields and reinsert record based on checkbox values

Posted on 2007-12-06
345 Views
Hi,

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
0
Question by:billium99
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 2
• 2

LVL 75

Assisted Solution

Michel Plungjan earned 100 total points
ID: 20425996

``````If you want the simple version:

function calc(theForm) {
var val = parseInt(theForm.formfield1.value,10)+
parseInt(theForm.formfield2.value,10)+
parseInt(theForm.formfield3.value,10)
theForm.totalFull.value=val;
theForm.totalThird.value=(theForm.onethird.checked)Math.round(.33*val):0;
theForm.totalFourth.value=(theForm.onefourth.checked)Math.round(.25*val):0;
}

where

<form>

<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
``````
0

LVL 5

Expert Comment

ID: 20426616
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, asp.net, perl etc. then I can give you the sample code in the specific server side script.
0

LVL 1

Author Comment

ID: 20427379
Hi,

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)

Thanks

Bill
0

LVL 5

Accepted Solution

TheGD earned 400 total points
ID: 20448141
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.

CheckBox.asp
============
<html>

<body>

<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>

<br><br>

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

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

</form>

</body>
</html>

CheckBoxSubmit.asp
=================
<html>

<body>

<%
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>"
else
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>"
else
Response.Write "NO" & "<br>"
end if

%>

</body>
</html>
0

LVL 1

Author Closing Comment

ID: 31413346
Thanks guys!
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…