The form submission did not yield any results

function calculateCost()
        {
            var projectorCost=0,price=0,quantity=0,discountPrice=0,totalCost=0;
            var modelName=document.getElementById('projectormodel').value;
            var quantity=document.getElementById('quantity').value;
            var couponCode=document.getElementById('couponcode').value;
            var res=document.getElementById('result');
            if(modelname=='Mobile Portable Projector')
            {
                price=30000;
                if(couponCode=='EveryCam45P'){
                    projectorCost=quantity*price;
                    discountPrice=projectorCost*0.1;
                    totalCost=projectorCost-discountPrice;
                   
                }
                else if(couponCode='EveryCam48P'){
                    projectorCost=quantity*price;
                    discountPrice=projectorCost*0.15;
                    totalCost=projectorCost-discountPrice;
                    
                }  
            }
            if(modelName=='Lumen DLP Projector'){
                price=31000;
                if(couponCode='EveryCam45P'){
                    projectorCost=quantity*price;
                    discountPrice=projectorCost*0.1;
                    totalCost=projectorCost-discountPrice;
                    
                }
                else if(couponCode='EveryCam48P'){
                    projectorCost=quantity*price;
                    discountPrice=projectorCost*0.15;
                    totalCost=projectorCost-discountPrice;
                    
                }
            }
            document.getElementById("res").innerHTML='Your total cost is Rs.'+totalCost;
            return false;
        }

My HTML and CSS are working fine, but the issue I'm having is with the JavaScript code. When I submit the form, it's not updating the inner HTML of the result ID as expected. I believe my JavaScript code may have some errors. Being a beginner in this language, I would appreciate any guidance on how to correct this.

Answer №1

There may be an issue with this code snippet:

var res=document.getElementById('result');
It should be corrected to:
var res=document.getElementById('result').value;
if you need the value. For retrieving inner HTML, use
var res=document.getElementById('result').innerHTML
or include your HTML file for clearer context.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Leverage the power of puppeteer alongside webpack

Struggling to make puppeteer work with webpack? Despite adding it to package.json and configuring webpack.dev, the 'launch' function still throws errors. Here's what I've tried: Installed dependency in package.json: npm i puppeteer In ...

JavaScript fails to focus on dynamically inserted input fields

Within my HTML template, there is an input element that I am loading via an Ajax call and inserting into existing HTML using jQuery's $(selector).html(response). This input element is part of a pop-up box that loads from the template. I want to set f ...

Waiting to run a function until a specified function has finished its execution

I have a piece of code that needs to address synchronization issues related to the execution order of MathJax functions. Specifically, I need to ensure that all the MathJax operations are completed before running the setConsoleWidth() function. What is t ...

Error: Property 'onclick' cannot be set on a null object

JavaScript isn't my strong suit, so I'm struggling to solve this issue. The console is showing me the following error message: Uncaught TypeError: Cannot set property 'onclick' of null <script> var modal = document.getE ...

Adding a CSS link to the header using JavaScript/jQuery

Is there a way to dynamically inject a CSS link located in the middle of an HTML page into the head using JavaScript? <head> ... styles here </head> <body> code <link href='http://fonts.googleapis.com/css?family=Lato:400,300, ...

performing a query on two tables with sequelize

There must be a more efficient way to accomplish this task with fewer lines of code. I am not very experienced with databases and I am new to sequelize and node. The user id is passed as a parameter and I need to check if there is a corresponding user in ...

Detecting key press events with extended duration using the DOM keydown event

Is there a way to receive notification when a key is pressed down, but not until it is released? It seems that using keydown continuously triggers the onkeydown callback while the key is held down. ...

JavaScript will continue to process the submit to the server even after validation has been completed

My current challenge involves implementing form validation using JavaScript. The goal is to prevent the form from being sent to the server if any errors are found. I have made sure that my JavaScript function returns false in case of an error, like so: ...

The system was unable to locate node.js with socket.io

I'm having trouble locating the file. According to the documentation I reviewed, socket.io is supposed to be automatically exposed. Encountered Error: polling-xhr.js?bd56:264 GET http://localhost:8081/socket.io/?EIO=3&transport=polling&t=LyY ...

What could be causing media queries to not update values even after being changed through JavaScript?

I have a simple navigation bar on my website, featuring links to different subpages. To enhance the user experience on mobile devices, I added a hamburger menu icon that is displayed on smaller screens. The links in the navigation bar are hidden using CSS ...

Having trouble displaying an image on a subpage in HTML

I've been struggling to display an image on one of my subpages using HTML. I suspect that the issue lies in how I am referencing the image file in the code. The image file is named crab.jpg and it is stored inside the pics folder within the Websites d ...

Ways to retrieve the position of hyperlinks within a div element

<div class="nav"> <a href="#item1">item1</a> <a href="#item2">item2</a> <a href="#item3">item3</a> </div> Looking at the HTML structure provided above, I am seeking to determine the index of the hyp ...

Utilize AJAX and JavaScript to retrieve file information and facilitate file downloads

I have developed a script that intercepts Captcha form submissions. Typically, when the form is submitted, a file will be downloaded (such as exe or zip) in the usual way where it appears at the bottom of the Chrome browser and gets stored in the "download ...

Unable to apply 100% height to flex child element

When it comes to creating a layout for my website, I have a simple idea in mind. I want the body content to take up at least 100% of the height of the page. This setup works perfectly on desktop screens, but when I switch to a mobile view (which changes th ...

Ways to decrease the size of this item while maintaining its child components?

Here is an object that I am working with: { "name": "A", "children": [ { "name": "B", "open": false, "registry": true, "children": [ { ...

Rendering High-quality Images in Internet Explorer Browser

Currently, I am working on optimizing my website for high resolution monitors, particularly the new iPad. The site is already formatted to my liking, with images having increased resolutions while still fitting into specific DIVs. For instance, an image wi ...

Saving a user with a BLOB avatar in Angular 5: Tips and Tricks for Success

As a newcomer to Angular, I am trying to figure out how to properly save a new user with an avatar. Can someone help me understand how to pass the Blob value of the avatar to my user Model for successful saving? Below is the code snippet I am working with ...

Text box input that displays the latter portion before the initial part

Looking for assistance with showing the end of the entered text rather than the beginning in an input field. For example, the input could be "Starting portion, Ending Portion". If the input field is limited to 14 characters, instead of displaying the firs ...

Include a "remember me" feature in the Stripe form

I am currently working on an exciting project using Angular 6. Within my website, I have decided to integrate the Stripe payment system. However, I would like to incorporate a unique and default "remember me" feature offered by Stripe. <div id="card-e ...

What's the best way to add vertical space to my DIV containing buttons?

Here is an example of HTML with CSS classes that float elements left and right: <div class="block-footer"> <button class="medium float-left">A</button> <button class="medium float-left">A</button> <button class="m ...