Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


recalculate fields and reinsert record based on checkbox values

Posted on 2007-12-06
Medium Priority
Last Modified: 2010-04-21

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
Question by:billium99
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
  • Learn & ask questions
  • 2
  • 2
LVL 75

Assisted Solution

by:Michel Plungjan
Michel Plungjan earned 400 total points
ID: 20425996

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


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.

Author Comment

ID: 20427379

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)



Accepted Solution

TheGD earned 1600 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.



<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



Author Closing Comment

ID: 31413346
Thanks guys!

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question