473,397 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

I like my code to run on click event.

1
I have coded a script and I got confused where I should call the function. I know to call it from the outside of it, but I want to implement a process entry function before the calculate function. I am stuck. I am posting a piece of the coding I have don:
Expand|Select|Wrap|Line Numbers
  1. "use strict";
  2. var $ = function (id) {
  3.     return document.getElementById(id);
  4.     //Asking for user entry.
  5. };
  6.  var processEntry = function() {
  7.             var entry = ($("income").value);
  8.             entry = parseInt($("income").value);
  9.             //Data validation for user entry.
  10.             if (isNaN(entry)) {
  11.                 alert(" Entry must be numeric");
  12.             }
  13.             //Variable declaration for calculate_tax function.
  14.             var tax = calculate_tax(income);
  15.             alert(tax);
  16.              };
  17.           //Creating a calculate function for  taxable income.
  18.  
  19.      var calculate_tax = function(income,tax){
  20.     //var income = parseFloat( $("income").value );
  21.    // $("tax").value =  calculate_tax(income);
  22.     //alert(tax);
  23.          var tax;     
  24.         // var calculate = 0;
  25.     if(entry <= 9275 ){
  26.         tax = (entry - 9275) * .10;
  27.     }
  28.     else if( entry <= 37650){
  29.     tax = (37650 - entry) * .15 + 927.5;     
  30.     }
I am not finish, but I want the data validation first and then the process entry function may process the calculate function data.
Oct 26 '19 #1
1 1705
gits
5,390 Expert Mod 4TB
well - so you have a process_entry function and a calculate_tax function. process_entry does some validation - so call that one onclick and when the validation was successful then call the calculate_tax method. At the moment you call the calculation even when the validation fails so that should be adapted. In line 14 you call the function with an undefined value though - but you you probably want to pass the entry value to it and calculate with it. Variables that you declare in one function are locally scoped - thus are not accessible outside the function - but you can pass them as parameters to other functions of course.

What is the exact problem that you have with it? The title and the description in the post might be a bit confusing at least for me. Is it how to access/passing the values around?

PS: for the parseInt method you should always provide the radix since it can lead to unintended results if its not provided.
Oct 28 '19 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Pete | last post by:
I have some funky form/event behavior. Access 97. Split frontend/backend, using Access security. I have the same behavior (or lack of behavior) for the pag_Click() event of two separate pages...
2
by: Liqun Xu | last post by:
Hallo NG, I created a Button with Click-Event dynamically: System.Web.UI.WebControls.Button bt_1 = new Button(); bt_1.Click += new EventHandler(bt_1_click); and I implemented the Funktion...
6
by: Michael Johnson Jr. | last post by:
I am trying to handle a button click event, which updates a web control table with data. The button is dynamically created in the table itself. When I call updateTable() in the Page_Load the new...
5
by: J McD | last post by:
Hi I have a DataGrid with an ImageButton column. When I click on an imagebutton I get a postback but it doesn't run the OnImgBtnClick method. I can actually comment out the line where I add this...
4
by: Mark Lingen | last post by:
I've found a problem with postback event handling and webcontrol buttons. Try out the following code in an ASP.Net project and you will see. Create a web project in VB.Net and drop this code...
41
by: JohnR | last post by:
In it's simplest form, assume that I have created a usercontrol, WSToolBarButton that contains a button. I would like to eventually create copies of WSToolBarButton dynamically at run time based...
0
by: Demetri | last post by:
I have created a web control that can be rendered as either a linkbutton or a button. It is a ConfirmButton control that allows a developer to force a user to confirm if they intended to click it...
15
by: Oleg Subachev | last post by:
I need to programmatically invoke from other class Click event of the Button on my Form. Button.OnClick method is protected, not public. How to perform this ? Oleg Subachev
3
by: Robert W. | last post by:
I'm new to ASP.net programming so excuse my ignorance if the following question seems overly simplistic. I've created a simple Login form with 3 primary WebControls: - A TextBox for the Username...
4
by: LyzH | last post by:
Someone else had a question on how to emulate a mouse click. I tried posting in that thread but I have something of a twist on this problem and I'm really in trouble here! If I don't get help...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.