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

Having difficulties testing the functionality of redux-form

I am struggling with testing react components that use redux-form. My integration tests are failing, indicating that I have not set up the tests correctly. There seems to be a consensus in discussions on this issue, both here and on GitHub. Any assistance ...

Warning: Angular JS encountered a [$injector:modulerr] error

I'm currently working on developing an application using the MEAN stack. Here is a snippet of my controller code: var myApp = angular.module('myApp',[]); myApp.controller('AppCtrl',['$scope', '$http', function( ...

Steps for adding SVGs to a <div> element

While there are numerous solutions on Stack Overflow detailing how to append an SVG in a div, none of them have proven successful for me. This could be due to my lack of experience with SVGs. Therefore, I am generating an SVG on my node server and the ...

Tips for accessing user input in JavaScript functions

In my ASP.NET code, I have created a dynamic image button and panel. Here is the code: Panel panBlocks = new Panel(); panBlocks.ID = "PanBlockQuestionID" + recordcount.ToString(); panBlocks.Width = 1300; panBlocks.Height = 50; panBlocks.BackColor = Color. ...

What is the best way to upgrade to a specific version of a child dependency within a module?

npm version: 7.24.2 Looking for assistance on updating a child dependency. The dependency in question is: vue-tel-input This dependency relies on libphonenumber-js with version ^1.9.6 I am aiming to update libphonenumber-js to version ^1.10.12. I have ...

Which method is more appropriate for my request - GET or POST? Or should I consider

Recently, I've been exploring the world of get and post methods and could use some guidance! Within my App.js file, there is a user text input field and a submit button. I have a couple of tasks in mind for handling this information: Retrieve a str ...

Dynamic Form Submission - Displaying Notifications for Success and Failure

While I have managed to successfully submit my form using PHP, I am currently facing some challenges with AJAX. Whenever I submit the form, an error message pops up as if 'res' is false instead of true. Despite my efforts to troubleshoot and rese ...

Guide for creating a CORS proxy server that can handle HTTPS requests with HTTP basic authentication

For my http requests, I've been utilizing a CORS-Proxy which works well for me. However, I recently stumbled upon an API for sending emails which requires http basic authentication for https requests. I'm uncertain of how to go about implementing ...

AngularJS: Struggling to Set Up Controller

I recently started my journey with AngularJS a few days back, and I've encountered this frustrating issue. Every time I run into this error: Error: ng:areq Bad Argument Argument 'NewStudentCtrl' is not a function, got undefined All my ot ...

Guide to using jQuery AJAX to read a JSON file

For the purpose of accessing and reading a json file from my server, I have employed the following code: $.ajax({ type:"GET", url:path, contentType:"application/json; charset=UTF-8", dataType:"json" success:function(response) { ...

Positioning a div to the right of another div within a container (box)

I'm currently trying to line up two divs alongside each other within a box. Using angularJS, I am dynamically generating input boxes and looking to include an image for the delete option next to each input box. Despite using "display: inline-block", I ...

Ensure that the divs are properly aligned and construct columns within a single column

I've been working on creating a step bar that needs to adapt to any number of steps provided by the backend. Here's what I have so far: https://i.sstatic.net/cj4qZ.png It looks fine, but connecting the circles with bars would be beneficial. How ...

Issue with Internet Explorer: Refusing to run javascript included in AJAX-loaded content

While loading AJAX content that includes a javascript function using the jQuery .load function with done() on completion, I am facing an issue. $('#content').load(a, done); function done() { if(pagejs() == 'function') { ...

What is the maximum width allowed for a WordPress site on mobile devices?

I have been tasked with addressing the responsiveness issues on mobile for this particular site. However, I am struggling to understand why the website is displaying horizontal scrolling on the landing page in a mobile view. Any assistance in resolving t ...

Steps for adding multiple images to a page in a React application:1. Create a

Having trouble displaying images on a React page. I have a directory with 30 images that I want to display on the page (.jsx file). Instead of exporting each image individually, is there a faster way to accomplish this task? Any ideas or suggestions would ...

"Encountered an issue while serializing the user for session storage in Passport.js. Have you already implemented code for

I have recently started learning nodejs and I am currently working on creating a login system. I followed the code for serializing the user from the passport documentation and placed it in config/passport.js. However, I keep encountering the error "Failed ...

React Component that closes when it loses focus

In my React project, I am working on creating a custom select2 style component. Most of the functionality is complete, but I am struggling with figuring out how to hide the result box when the user clicks away. Here is the render method: render() { l ...

How can I attach :after and :before pseudo-elements to a submit button?

I'm attempting to enhance my submit button with :after/:before elements, but I'm having trouble getting it to work properly. Specifically, I want to add a swipe (Sweep To Right) transition effect on the button from left to right. Similar to - th ...

Utilize Ag Grid to selectively apply borders between grouped values

I have included my Plunker link: [https://plnkr.co/edit/lnF09XtK3eDo1a5v] Is there a way to add borders between different group values? For example, in this case, 'country' is the group and when all rows for United States are completed, can we a ...

The dynamic duo: Selenium and HTML!

For the past few days, I've been using selenium to extract information from a private database of company data. Unfortunately, due to the password protection of the database, I can't share the entire python code or HTML code. Here is the specifi ...