Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 9th, 2006, 07:37 AM
Authorized User
 
Join Date: Jan 2006
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default Calculating text fields

I am using Dreamweaver 8 and vbscript in asp pages.
I have text fields where a user will enter scores into each field.
I need the "total score" field to calculate the data entered into the other fields and to total up the marks as data is entered into each field.

For example on one page i have fields called StartWord,Typing,Deleting,Perform. Each field has a text box assigned to it.

I have an asp page that posts all submitted data to an access data base. Do i write code in the access database in one of the fields in design view or do i write some type of code in the asp page that submits the data?

Does anyone know how to go about doing this?

Reply With Quote
  #2 (permalink)  
Old February 26th, 2006, 10:22 AM
Friend of Wrox
 
Join Date: Nov 2005
Location: Rotterdam, , Netherlands.
Posts: 223
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi jayman,

It's not really clear wat you want to do to me.
1. What do you want to do with the value's in the input fields.
2. What do you need the database for.

If you want to calculate the total score using only the input fields this is how I would do it.
you will need 2 pages.
1. The form page.
2. The request page with this page you
    - calculate the total score
    - display the total score
    - (optional) save this score to a database.

If I'm completely wrong about your question let me know and and I'll help.







__________________________________________________ ________
This is my junk I'm gona eat it
Reply With Quote
  #3 (permalink)  
Old February 27th, 2006, 04:57 AM
Authorized User
 
Join Date: Jan 2006
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

thanks for replying. I thought i was totally clear.
I have several text fields\boxes in a form. I want the last text box to display and calculate the total score when scores are entered in the other text boxes. That's it. The data is already submitted to a database when the form is submitted. I just want the total score box to display the total score and be submitted to the database just like all the other data.

I haven an action asp page that submits any data entered into the form to an access database. I just want to know do i write some sort of code into the same action page to calculate the total score.

Thanks

Jayman












Quote:
quote:Originally posted by Dj Kat
 Hi jayman,

It's not really clear wat you want to do to me.
1. What do you want to do with the value's in the input fields.
2. What do you need the database for.

If you want to calculate the total score using only the input fields this is how I would do it.
you will need 2 pages.
1. The form page.
2. The request page with this page you
    - calculate the total score
    - display the total score
    - (optional) save this score to a database.

If I'm completely wrong about your question let me know and and I'll help.







__________________________________________________ ________
This is my junk I'm gona eat it
Reply With Quote
  #4 (permalink)  
Old February 27th, 2006, 05:44 AM
Friend of Wrox
 
Join Date: Nov 2005
Location: Rotterdam, , Netherlands.
Posts: 223
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Now I see,

You need javascript DOM.
This can calcutalte the numbers on the moment you enter the values.
I'll help you with it if you have trouble with javascript DOM.

Hint you'll need onKeyUp.

goodluck.


__________________________________________________ ________
This is my junk I'm gona eat it
Reply With Quote
  #5 (permalink)  
Old February 27th, 2006, 05:50 AM
Friend of Wrox
 
Join Date: Jul 2003
Location: , , United Kingdom.
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Jayman,

If you want to calculate the total client-side before posting, you can do this with client-side scripting.

Can you post the code for your form and your calculation requirements?

Cheers,

Chris

Reply With Quote
  #6 (permalink)  
Old February 27th, 2006, 07:18 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

My JS is average but I found your objective useful for me to have a go. Try:

----cut n paste code: name your page addScoreswithJS.asp-----
<html>
 <head>
  <title>calculate client side values</title>
  <script>
  function validateScores()
  {
     if(document.theForm.s1.value == "")
     {
        alert("Please enter a score in box one");
        document.theForm.s1.focus();
        document.theForm.s1.select();
        return(false);
     }
     if(isNaN(parseInt(document.theForm.s1.value)))
     {
        alert("The value in box one must be an integer");
        document.theForm.s1.focus();
        document.theForm.s1.select();
        return(false);
     }
     if(document.theForm.s2.value == "")
     {
        alert("Please enter a score in box two");
        document.theForm.s2.focus();
        document.theForm.s2.select();
        return(false);
     }
     if(isNaN(parseInt(document.theForm.s2.value)))
     {
        alert("The value in box two must be an integer");
        document.theForm.s2.focus();
        document.theForm.s2.select();
        return(false);
     }
     document.theForm.posted.value = "y";
     return(true)
  }

  function addScores(scoreValue)
  {
     var scoreOne;
     scoreOne = (scoreValue);
     parseInt(scoreOne);
     parseInt(document.theForm.RunningTotal.value);
     (document.theForm.RunningTotal.value = (document.theForm.RunningTotal.value + parseInt(scoreOne)));
  }

  function resetValues()
  {
     document.theForm.s1.value='';
      document.theForm.s2.value='';
     document.theForm.RunningTotal.value='';
     document.theForm.posted.value = '';
  }
  </script>
 </head>
<body>
<%
   if request.form("posted") = "y" then
      response.write "<b>The form has been posted - your total is " & request.form("RunningTotal") & "</b>"
   else
      response.write "<B>Enter scores - the last box should calculate and display the runing total.</b>"
   end if
%>
<form name="theForm" method="post" action="addScoreswithJS.asp" onsubmit="return validateScores();">
<input type="hidden" name="posted" value="">
<table>
 <tr>
  <td>Score One:</td>
 </tr>
 <tr>
  <Td><input type="text" name="s1" value="<% if request.form("s1") <> "" then response.write request.form("s1") end if %>" size="5"></td>
 </tR>
 <tr>
  <td>Score Two:</td>
 </tr>
 <tr>
  <Td><input type="text" onClick="javascript:addScores(document.theForm.s1. value);" value="<% if request.form("s2") <> "" then response.write request.form("s2") end if %>" name="s2" size="5"></td>
 </tR>
 <tr>
  <td><B>Running Total</b></td>
 </tr>
 <tr>
  <td><input type="text" name="RunningTotal" value="<% if request.form("RunningTotal") <> "" then response.write request.form("RunningTotal") end if %>" size="5"></td>
 </tr>
 <tr>
  <td><input type="submit" name="Submit" onClick="javascript:addScores(document.theForm.s2. value);">&nbsp;&nbsp;<INPUT type="button" value="Reset Values" onClick="resetValues();"></td>
 </tr>
</table>
</form>
</body>
</html>
-------------------------------------------------------------

Wind is your friend
Matt
Reply With Quote
  #7 (permalink)  
Old March 2nd, 2006, 10:46 AM
Authorized User
 
Join Date: Jan 2006
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Chris,

I have a one page form with about 10 sets of text boxes on it.
At the end of each set of text boxes there is a box called Total score. Which should display the total score once data is input into the other text boxes.

I have this code so far that works:

function calculate(What) {
    for (var i=1,Total_Score1=0;i<3;i++)
       Total_Score1 += What.elements['Textfield' + i].value - 0;
    What.Total_Score1.value = Total_Score1;

This formula calculates the total score in a text box called Total Score1. Problem im having is that all the other text boxes are called some different e.g Total score1, Total score2 etc.

The other textfields that the user inputs scores into are called textfield1 etc. So that the formula adds up the scores no matter what u put in the text box.

How do i get the formula to calculate the total score for text boxes with the name of Total_score2,Total_score3 etc.

Jayman



Quote:
quote:Originally posted by ChrisScott
 Hi Jayman,

If you want to calculate the total client-side before posting, you can do this with client-side scripting.

Can you post the code for your form and your calculation requirements?

Cheers,

Chris

Reply With Quote
  #8 (permalink)  
Old March 2nd, 2006, 10:57 AM
Friend of Wrox
 
Join Date: Jul 2003
Location: , , United Kingdom.
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Jayman,

Ok, I think I get what you mean.

What are the names of the text boxes that you are going to add up for Total_Score2, Total_Score3 etc - do they continue as Textfield3, Textfield4 and so on?

Does each Total_Score[n] have the same number of text boxes to add up?

Cheers,

Chris

Reply With Quote
  #9 (permalink)  
Old March 2nd, 2006, 06:20 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

jayman - Does the code I posted not meet your requirement?

Wind is your friend
Matt
Reply With Quote
  #10 (permalink)  
Old March 3rd, 2006, 06:06 AM
Authorized User
 
Join Date: Jan 2006
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks for your efforts but that not quite what i was looking for.

Jayman

Quote:
quote:Originally posted by mat41
 jayman - Does the code I posted not meet your requirement?

Wind is your friend
Matt
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
populating online text fields etc hamilton C# 2 June 20th, 2007 09:16 AM
Select fields & calculating age miki-pt Access ASP 1 November 26th, 2006 06:16 PM
Combining Text Fields lizhaskin Access VBA 1 May 1st, 2006 06:15 AM
specifying number of text fields Astro VB How-To 64 August 9th, 2005 08:02 PM
MySQL Text Fields MAtkins General .NET 0 May 27th, 2005 03:17 PM



All times are GMT -4. The time now is 07:32 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.