Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8249861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:41:13+00:00 2026-06-07T23:41:13+00:00

I am VERY NEW to javascript and am messing around with some math. I

  • 0

I am VERY NEW to javascript and am messing around with some math. I currently have:

<input disabled="disabled" type="text" id="backer-prediction-answer" width="100" value="" />

<FORM> 
    <INPUT type="button" value="Apply" name="button1" onclick="apply()">
</FORM>

<script>
var backerPrediction1 = document.getElementById("backer-prediction-1").value;
var backerPrediction2 = document.getElementById("backer-prediction-2").value;
var backerPrediction3 = document.getElementById("backer-prediction-3").value;
var backerPrediction4 = document.getElementById("backer-prediction-4").value;

function apply(){
    var backers = parseInt(backerPrediction1,10) + parseInt(backerPrediction2,10);
    document.getElementById("backer-prediction-answer").value = (backers);
}
</script>

I would like to be able to hit apply and have it recalculate. Do I need to delete the variable before declaring it again? If so, how do I do that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T23:41:16+00:00Added an answer on June 7, 2026 at 11:41 pm

    Move the variables backerPredictionX inside the function, so that they are evaluated everytime you apply()

    <script>
    
    function apply(){
        var backerPrediction1 = document.getElementById("backer-prediction-1").value;
        var backerPrediction2 = document.getElementById("backer-prediction-2").value;
    
        var backers = parseInt(backerPrediction1,10) + parseInt(backerPrediction2,10);
        document.getElementById("backer-prediction-answer").value = (backers);
    }
    </script>
    

    With jquery (code not validated):

    function apply(){
        var backerPrediction1 = $("#backer-prediction-1").val();
        var backerPrediction2 = $("#backer-prediction-2").val();
    
        var backers = parseInt(backerPrediction1,10) + parseInt(backerPrediction2,10);
        $("#backer-prediction-answer").val(backers);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm very new to javascript and have been playing around with regular expressions. I'm
I am very new Javascript and am messing around trying to make a simple
Very new to javascript and html-type stuff. I wanted to just make a quick
I have this Javascript code I inherited from another developer. I am very new
I am new to javascript so sorry I don't know very much. I have
I am very new in Javascript. I want to make some basic stuffs that
I am very new to javascript and hit a wall. Basically I have a
I'm very new to javascript (started messing with it today). I'm trying to change
I'm very new to JQuery and don't have much experience with javascript at all,
I am very new to javascript and have been using the JQuery library quite

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.