Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

196
Views
JSP and AJAX for stock quotation

As an exercise, I'm trying to create a simple page where you have two stock quotation, set to starting values 100 and 200. The methods updateValues() modify the quotation value by +/-1% and the displayAction() method return the String "<name of the quotation> = <value of the quotation>". Anyway, if I click the button "Refresh Values" the two quotation doesn't change. Wat I'm doingo wrong?
Here's my index.jsp:

<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<jsp:useBean id="enel" class="it.unitn.studenti.porcelli.leonardo.esamefebbraio2022.businessobject.Enel" scope="application"></jsp:useBean>
<jsp:useBean id="webuild" class="it.unitn.studenti.porcelli.leonardo.esamefebbraio2022.businessobject.WeBuild" scope="application"></jsp:useBean>
<!DOCTYPE html>
<html>
<head>
    <title>PWEB Banking</title>

</head>
<body>
<script>
    function startIsClicked(){
        document.querySelector("#start_button").disabled = true;
        document.querySelector("#stop_button").disabled = false;
    }
    function stopIsClicked(){
        document.querySelector("#start_button").disabled = false;
        document.querySelector("#stop_button").disabled = true;
    }
    function refreshValues(enel, webuild){
        const xhttp = new XMLHttpRequest();
        xhttp.onload = function (){
            const newEnelValue = <%enel.updateValue();%>;
            document.getElementById("Enel").innerHTML = enel.displayAction();
            const newWebuildValue = <%webuild.updateValue();%>;
            document.getElementById("Webuild").innerHTML = webuild.displayAction();
        }
        xhttp.open("GET", "index.jsp", true);
        xhttp.send();
    }

</script>
<div id="buttons">
    <button id="start_button" type="button" name="start" onclick="startIsClicked()">Start</button>
    <button id="stop_button" type="button" name="start" onclick="stopIsClicked()" disabled>Stop</button>
</div>
<div id="Enel">
    <%=enel.displayAction()%>
</div>
<div id="Webuild">
    <%=webuild.displayAction()%>
</div>
<button type="button" onclick="refreshValues(<%=enel%>, <%=webuild%>)">Refresh Values</button>
<br/>
</body>
</html>
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!