Solved

recalculate fields and reinsert record based on checkbox values

Posted on 2007-12-06
5
344 Views
Last Modified: 2010-04-21
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
Comment
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
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 75

Assisted Solution

by:Michel Plungjan
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

Open in new window

0
 
LVL 5

Expert Comment

by:TheGD
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

by:billium99
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

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

by:billium99
ID: 31413346
Thanks guys!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

733 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