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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:21:11+00:00 2026-05-31T04:21:11+00:00

I am trying to get this script to work, but it is failing somewhere

  • 0

I am trying to get this script to work, but it is failing somewhere in the last alert. The script is supposed to pull everything from a form, and then spit out the results as an alert box. I’m pretty sure my html is correct.

function calcServiceTotal() {
var animalName = document.getElementById("name").value;
var ownerName = document.getElementById("owner").value;
var currentDate = document.getElementById("date").value;
var choosenService = document.getElementById("service");
var serviceName = choosenService.options[choosenService.selectedIndex].text;
var serviceCost = document.getElementById("value").value;
var taxCost = serviceCost * 0.07;
var totalCost = serviceCost + taxCost;
if (animalName == null || animalName == "")
    {
    alert("Please give us your pet's name.");
    return false;
    }
else if (ownerName == null || ownerName == "")
    {
    alert("Please give us your name.");
    return false;
    }
else if (currentDate== null || currentDate == "")
    {
    alert("Please give us a date.");
    return false;
    }
else
    {
    alert("Pet's Name:" + animalName + '\n' + "Owner's Name:" + ownerName + '\n' + "Service:" + choosenService + '\n' + "Cost: $" + serviceCost.toFixed(2) + '\n' + "Tax: $" + taxCost.toFixed(2) + "Total Cost:" + totalCost.toFixed(2));
    }
}

Here is the relevant html code.

<table width="339" border="0">
          <tr>
            <td width="329"><strong>Patient Information</strong></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
          </tr>
          <tr>
            <td>Name: &nbsp;&nbsp;
            <label for="textfield"></label>      <input type="text" name="textfield" id="name" /></td>
          </tr>
          <tr>
            <td>Owner: &nbsp; 
            <input type="text" name="textfield2" id="owner" /></td>
          </tr>
          <tr>
            <td>Date: &nbsp;&nbsp;&nbsp;
          <input type="text" name="textfield3" id="date" /></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
          </tr>
          <tr>
            <td><strong>Services</strong></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
          </tr>
          <tr>
            <td><form id="form1" name="form1" method="post">
              Select a Service:
              <label for="select"></label>
              <select name="select" id="service">
                <option>Basic Appointment - $50</option>
                <option>Extended Appointment - $75</option>
                <option>Vacination - $25</option>
                <option>Grooming - $35</option>
                <option>Bathing - $35</option>
                </select>
            </form></td>
          </tr>
          <tr>
            <td>Service Fee (from above): &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
              <label for="textfield4"></label>
                <input type="text" name="textfield4" id="value" />
            </td>
          </tr>
          <tr>
            <td><form id="form2" name="form2" method="post" action="">
              <input type="button" onclick="calcServiceTotal();" name="button" id="button" value="calculate"/>
            </form></td>
          </tr>
        </table>
  • 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-31T04:21:13+00:00Added an answer on May 31, 2026 at 4:21 am

    The problem is you’re using a function that is not defined, namely toFixed()

    It is easy to find these errors if you use a debugging tool such as Firebug:

    enter image description here

    To clarify, toFixed is a function, but even though Javascript is loosely typed, in the context it’s supplied your are applying toFixed to a string (for which it is undefined) and in this context the string cannot be coerced into a number.

    You must specify it manually, by changing your last alert to:

    alert("Pet's Name:" + animalName + '\n' + "Owner's Name:" + ownerName + '\n' + "Service:" + choosenService + '\n' + "Cost: $" + Number(serviceCost).toFixed(2) + '\n' + "Tax: $" + Number(taxCost).toFixed(2) + "Total Cost:" + Number(totalCost).toFixed(2));

    Note that there are other errors in your code, such as concatenating two string values (which store Numbers) instead of addition.

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

Sidebar

Related Questions

I'm trying to get this piece of script to work, but it keeps dying
I have been trying everything I can to get this script to work and
I am trying to get this script to work. it opens up a directry
I'm trying to get this simple PowerShell script working, but I think something is
I am trying to get this simple script to work. Basically, when a user
I'm trying to get this to work, but I am having issues. What am
I've been trying to get this arrow toggle script work on my page. I
I've been trying to get this to work but it's got me stumped. I
Hi I have been trying to get this script http://jsbin.com/ipajo5/ working but using .live()
Yo, i'm trying to do this script working, but it doesn't work. How do

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.