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 6052033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:52:58+00:00 2026-05-23T07:52:58+00:00

I’ve got a very simple form on an HTML page I’ve done which works

  • 0

I’ve got a very simple form on an HTML page I’ve done which works as follows. There are 2 buttons on the page “calculate” and “reset” The user inputs 3 numbers and when they click “calculate” it add’s the values together and also calculates 1%, 2% and 3% of each number (and add’s those values together too). The output is displayed in a table which looks something like this:

input %
input %
input %
total total
calculate reset

Now my rather annoying problem is that I have replaced the buttons with images and since I’ve done this, once I click ‘calculate’ the values do not stay populated in the form and rather annoyingly in FF the page “refreshes” and skips back to the top too! What am I doing wrong? Here’s the JS:

var sInput,dInput,pInput,inputTotal,sMonthly,dMonthly,pMonthly,sAnnual,dAnnual,pAnnual,monthlyT    otal,annualTotal;

function takeInput()
{
sInput=parseFloat(document.forms[0].txt1st.value);
dInput=parseFloat(document.forms[0].txt2nd.value);
pInput=parseFloat(document.forms[0].txt3rd.value);
inputTotal=sInput+dInput+pInput;
document.forms[0].spendtotal.value="£ " + inputTotal;
}

function isNan() 
{
    if (isNaN(sInput || pInput || dInput) == true) {
        alert("You entered an invalid character. Please reset the form.");
    }
    else {
        return(false);
    }
}  

function calculateMonthly()
{
sMonthly=sInput*0.01;
dMonthly=dInput*0.02;
if (pInput >= 300) {
    pMonthly=300*0.03;
}
    else
{
pMonthly=pInput*0.03;
}
monthlyTotal=sMonthly+dMonthly+pMonthly;
//rounded up numbers to the nearest whole number
//i.e. .5+
document.forms[0].supermarket.value="£ " + Math.round(sMonthly);
document.forms[0].deptstores.value="£ " + Math.round(dMonthly);
document.forms[0].petrol.value="£ " + Math.round(pMonthly);
document.forms[0].monthlytext.value="£ " + Math.round(monthlyTotal);
}

function calculateAnnual()
{
    sAnnual=sMonthly*12;
    dAnnual=dMonthly*12;
    pAnnual=pMonthly*12;
    annualTotal=sAnnual+dAnnual+pAnnual;
    document.forms[0].supermarketAnnual.value="£ " + Math.round(sAnnual);
    document.forms[0].departmentstoreAnnual.value="£ " + Math.round(dAnnual);
    document.forms[0].petrolAnnual.value="£ " + Math.round(pAnnual);
    document.forms[0].annualresult.value="£ " + Math.round(annualTotal);

}

And here’s the code from the form:

<input type="image" src="calculate-btn.gif" onClick="takeInput();calculateMonthly();calculateAnnual();">

<input type="image" src="reset-btn.gif" />

Weird thing is, if I don’t use images then the form stays populated with the output and the buttons work fine. Please be gentle, I am a total Javascript Noob.

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-23T07:52:59+00:00Added an answer on May 23, 2026 at 7:52 am

    I think the image button is acting as a submit button and posting the form to the server. Try this:

    <input type="image" src="calculate-btn.gif" onClick="takeInput();calculateMonthly();calculateAnnual();return false;">
    

    The return false will cancel submission of the form.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a text area in my form which accepts all possible characters from
i got an object with contents of html markup in it, for example: string
I'm making a simple page using Google Maps API 3. My first. One marker
I have just tried to save a simple *.rtf file with some websites and
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

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.