Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP to Access; form field auto-calculation 1

Status
Not open for further replies.

Xunil

Technical User
Dec 17, 2002
27
0
0
GB
This is the scenario:

I want to be able to input a numerical value in a form field.

Depending on that value, the form field below it will automatically populate with another numerical value.

In Excel I do it like this:

=IF(L2>=1000001,"700",IF(L2>=500001,"420",IF(L2>=200001,"220",IF(L2>=100001,"150",IF(L2>=80001,"100",IF(L2>=50001,"60",IF(L2<=50000,"40")))))))

Basically if the input value of text box 1 is greater than 1,000,001 then the next text box will read 700

At greater than or equal to 500,001 it will read 420.

And so on...

I would also like to add a third text box that will automatically calculate a percentage based on the first text box value, so if text box 1 is greater than or equal to 500,001 then text box 3 will equal 4% of the value of text box 1

That's the easiest way to describe what I'm trying to achieve.

Eventually I'd like to incorporate VAT calculations and other bits and bobs, all of which will be saved into the database when a save/submit button is clicked.

All I've managed so far is a very large headache.

Any (polite) suggestions gratefully received.
 
Do you have any relevant code that you have used to do accomplish what you are trying to do? It would make it easier to help you fix what you are trying to do.

Based on your description, it sounds like what you are looking for could easily be accomplished using client-side code. You could use the client-side code to validate that the users only enter a numerical value in the first textbox and then, after they update the first textbox with a numeric value, then populate the second textbox with whatever value you desire.

You could also do the same thing server-side, it just requires (IMO) an unnecessary trip to the server.

Some pseudo-code to perhaps help you get started (if you haven't yet gotten that far) - this is NOT actual code, you will need to do some more research if you're unfamiliar with it:
Code:
function UpdateTextbox  [COLOR=green]//This is the client-side function that will be called to perform the updates/validation to your textboxes. [/color]
{
if frmMain.Textbox1.value is not a number then
  alert("This box must contain a number!");
  frmMain.Textbox1.focus;
  frmMain.Textbox1.select;
else
  if frmMain.Textbox1.value >= 1000001 then
    frmMain.Textbox2.value = 700
  if frmMain.Textbox1.value >=500001 && frmMain.Textbox1.value <= 1000000 then
    frmMain.Textbox2.value = 420
  [COLOR=green]//You can add whatever else you want in here as well. [/color]
end
}

<form name="frmMain">
<input type="textbox" name="Textbox1" id="Textbox1" onupdate="UpdateTextbox;">
<br>
<input type="textbox" name="Textbox2" id="Textbox2">
</form>

------------------------------------------------------------------------------------------------------------------------
"Men occasionally stumble over the truth, but most of them pick themselves up and hurry off as if nothing ever happened."
- Winston Churchill
 

also, for client side stuff:

javascript: forum216


A smile is worth a thousand kind words. So smile, it's easy! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top