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

  • Home
  • SEARCH
  • 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 6720431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:12:41+00:00 2026-05-26T09:12:41+00:00

<SCRIPT Language = JavaScript> function calculate() { a = 12 b = eval(document.form.number.value) c

  • 0
<SCRIPT Language = JavaScript>
function calculate() {
a = 12
b = eval(document.form.number.value)
c = 5J7S
d = (a + b + c)
alert(d)

}
</SCRIPT>

<FORM NAME = form>

Phone: <INPUT TYPE = text SIZE = 3 value ="">
-
<INPUT TYPE = text name = number SIZE = 3 value ="">
-
<INPUT TYPE = text SIZE = 4 value ="">

<P>
<Input Type = Button NAME = b1 VALUE = "Grab Code" onClick = calculate() 

</FORM>

5JG7S (Fixed Value)

5+7=12 (Added both numbers from Fixed Value)

Phone number 123-456-7890
4+5+6=15 (Prefix added together)
12+15=27 (Added numbers from the Fixed Value and the numbers that were added from the prefix)
27+5JG7S=275JG7S (Those numbers were added to the beginning of the orginal Fixed Value)

Now this Script that I have:
a is the added numbers from the Fixed Value
b is the input from the form(phone number)
c is the Fixed Value
d is adding each one up so they will display the code as an alert.

Now, if I take out c and just add a and b it performs the addition, if c is in there, it stops the process and produces nothing.

My question is, how do we add the calculated number and append it to the beginning of the fixed value?

Also, the addition works, but not the way I want it to, I want to add the 3 numbers together, the javascript adds 456+12= 468

I know this is very simple code, I am not familiar with Javascript programming and I pretty much pieced together what I found from searching.

I hope this makes sense, if this is not possible I understand.

Thanks!

  • 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-05-26T09:12:41+00:00Added an answer on May 26, 2026 at 9:12 am

    using parseInt on the values should help with the math. your results are currently inaccurate because the form values are strings: rather than adding numbers you are concatenating strings.

    i changed your ‘number’ input to have an ID attribute, so that you can select with getElementById and replaced the eval call with a call to parseInt.

    the value of c in the calculate function needs to be corrected though, not sure what you meant but that will generate an error.

    other various HTML tidyness issues (nothing that would break, just easier to read IMHO).

    <script type="text/javascript">
    function calculate() {
        var a = 12;
        var b = parseInt(document.getElementById("number").value);
        // var c = 5J7S; 
        var d = (a + b + c);
        alert(d);
    }
    </script>
    
    <form name="form">
    
    Phone: <input type="text" size="3" value=""/>
    -
    <input type="text" name="number" id="number" size="3" value=""/>
    -
    <input type="text" size="4" value=""/>
    
    <p>
    <input type="button" name="b1" value="Grab Code" onclick="calculate()"> 
    </p>
    </form>
    

    hope that helps! cheers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code in the HEAD: <script LANGUAGE=JavaScript> <!-- function calculate(form) { height
For example: script.js: function functionFromScriptJS() { alert('inside functionFromScriptJS'); } iframe.html: <html> <head> <script language=Javascript
HI, I've got: <script language=javascript type=text/javascript> $(document).ready(function() { $(#thumbs a).click( function() { var BGswitch
I have this simple code that speaks for itself. <script language='javascript"> function check() {}
<script LANGUAGE=JavaScript> function confirmSubmit() { jConfirm('Is the Appointment Confirmed?', 'Confirmation Dialog', function(r) { if(r)
I am trying to use the following script in asp.net: <script language=javascript type=text/javascript> function
Okay, I have this code: <script language=javascript type=text/javascript> <!-- function requestPage(page) { var request
I found this script: <script language=Javascript TYPE=text/javascript> var container = document.getElementById('dl'); var seconds =
For simplicity, i have the following file named test.jsp: <script language=javascript> alert(a$b.replace(/\$/g,k)); </script> I
See example: <!DOCTYPE html> <html> <head> <title>language</title> <script type=text/javascript src=http://www.google.com/jsapi> </script> </head> <body> <div

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.