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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:09:08+00:00 2026-05-27T04:09:08+00:00

Hi I am trying to make a basic form that adds a value of

  • 0

Hi I am trying to make a basic form that adds a value of £1.50 on to total price if check box is checked. So i have a user input a price (value for a voucher) they can either pick up or get it delivered – delivery is £1.50.

I have a basic knowledge of javascript and found the following code that allows me to add two form fields together –

<script type="text/javascript"><!--
function updatesum() {
document.form.sum.value = (document.form.sum1.value -0) + (document.form.sum2.value -0);
}
//--></script>

html

<form name="form" >
Enter a number:
<input name="sum1" onChange="updatesum()" />
and another number:
<input type="checkbox" name="sum2" onChange="updatesum()" value="1.50" checked> 
Their sum is:
<input name="sum" readonly style="border:0px;">
</form>

obviously this works but again obviously the value stays at 1.50 whether the box is checked or not – so i need help with an “if” statement. have searched around but really am quite stuck.

  • 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-27T04:09:09+00:00Added an answer on May 27, 2026 at 4:09 am

    You need to only add the value if the checkbox is checked.

    <script type="text/javascript">
    function updatesum() {
         var deliveryFee = document.form.sum2.checked ? Number(document.form.sum2.value) : 0;
         document.form.sum.value = (document.form.sum1.value -0) + deliveryFee;
    }
    </script>
    

    You might want to consider using a framework like jQuery to help with this. It will make it easier to write your code and help you keep your code separate from your HTML, improving it’s readability and your ability to debug it.

    <form name="form" >
        Enter a number:
        <input id="voucher" name="cost" />
        and another number:
        <input type="checkbox" id="deliveryFee" name="fee" value="1.50" checked="checked" > 
        Their sum is:
        <input id="total" name="sum" readonly style="border:0px;">
    </form>
    
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.js"></script>
    <script type="text/javascript">
        $(document).ready( function() {
            $('#voucher,#deliveryFee').change( function() {
                 var fee = Number( $('#deliveryFee:checked').val() || 0 );
                 var cost = Number( $('#voucher').val() );
                 $('#total').val( cost + fee );
            });
         });
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to make a custom :confirm message for a rails form that returns data
I have a c# app and I'm trying to write a basic login form
I'm trying to figure out how make a basic GET request using Network.HTTP.simpleHTTP that
I'm trying to make the following form in JSF 2.0 but a have some
I'm trying to make a basic Address class, that many different other classes can
Trying to make a make generic select control that I can dynamically add elements
Im trying to make a function that will return an element of type point:
What I am trying to do is make a form in Access and with
I'm trying to make a BASIC roulette script. Is there anyway to get the
I'm trying to make a basic model of the solar system in Direct X.

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.