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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:09:07+00:00 2026-06-01T03:09:07+00:00

I have a problem with a script and I don’t know how to handle

  • 0

I have a problem with a script and I don’t know how to handle it.
I’m trying to make a simple calculator that displays how much you must pay for a random model. I’m trying to display a different answer depending upon the amount of time and advance chosen in the select menu. The formulas in each if statement does actually work when I simply list the variables outside of if statements displaying each answer in a series of alert boxes, but I’d like to display only the applicable answer.What I am doing wrong?
Escuse my rudimentary JS skills butt I am still a beginner in this domain.Thanks for your time.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Calculator</title>


<script script language="javascript" type="text/javascript">
function  rata() {
    var selection1 = document.getElementsById("model")[0].value;;
    var selection2 = document.getElementsById("time")[1].value;;
    var selection3 = document.getElementsById("advance")[2].value;;

    if(selection2 === "t1" && selection3 === "a1"){
        var pay1 = "100 euro";
        alert("You must pay"  +  pay1  +  ".");
    }
    else if(selection2 === "t1" && selection3 === "a2"){
        var pay2 = "200 euro";
        alert("You must pay"  +  pay2  +  ".");
    }
    else if(selection2 === "t2" && selection3 === "a1"){
        var pay3 = "400 euro";
        alert("You must pay"  +  rata3  +  ".");
    }
    else if(selection2 === "t2" && selection3 === "a2"){
        var pay4 = "800 euro";
        alert("You must pay"  +  pay4  +  ".");
    }
}
</script>

</head>

<body>

                    <form name="calculator">
                        Model <br><select name="model" id="model"> 
                                        <option value="">selectati modelul</option>
                                        <option value="model">Model 1</option>
                                        <option value="model">Model 2</option>
                                        <option value="model">Model 3</option>
                                        <option value="model">Model 4</option>
                                        <option value="model">Model 5</option>
                                        <option value="model">Model 6</option>
                                        <option value="model">Model 7</option>
                                        <option value="model">Model 8</option>
                                  </select><br>
                        Time <br><select name="time" id="time">
                                        <option value="">select time</option>
                                        <option value="t1">1 year</option>
                                        <option value="t2">2 years</option>
                                  </select> <br>
                        Advance <br><select name="advance" id="advance">
                                        <option value="" >select advance</option>
                                        <option value="a1" >0%</option>
                                        <option value="a2" >50%</option>
                                  </select> <br>
                                  <input type="button" value="Send" onclick="pay()">
                    </form> 


</body>
</html>
  • 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-01T03:09:09+00:00Added an answer on June 1, 2026 at 3:09 am

    <input type="button" value="Send" onclick="pay()"> <— this calls “pay()”, but your function is called “rata()”

    document.getElementsById("model")[0].value; <– there is no such function, it’s not plural, it should be: getElementById

    document.getElementById("model")[0].value; will never give you the value of a SELECT. Use this:

    var sel1 = document.getElementById("model")
    var val1 = sel1[sel1.selectedIndex].value
    

    Since you’re getting the value, and all of the values are “model” you will get the same value regardless of what the user chooses.

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

Sidebar

Related Questions

I have a problem. I built a script to make a request to an
Hello I'm using flexigrid and i have a problem, i don't know why it
I don't really understand what's going on here. I have a jquery script that
i have a problem with my script i have a method that return a
I have a hefty PHP script. So much so that I have had to
I have a problem writing a script that will prevent default behavior of submit
Being jQuery noob I have a problem and I don't know how to solve
He all, i have a problem with my bash script. That's my code: #!/bin/bash
I have a problem with following script. It generates a list of places which
I have a problem with a bash script. I have to use the operator

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.