Solved

recalculate fields and reinsert record based on checkbox values

Posted on 2007-12-06
5
341 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
  • 2
  • 2
5 Comments
 
LVL 75

Assisted Solution

by:Michel Plungjan
Michel Plungjan earned 100 total points
Comment Utility

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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks guys!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
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…

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now