Danny_501 2 Junior Poster

Hi, I'm trying to make a label visible by clicking on a button. The following code will make the label visible, but will disappear in less than a second. I'm assuming its because the form is getting submitted in the java script, so the page is getting refreshed? Is there a different way of doing this, say in the JSP?

<body>
    <%
        PumpController pc = new PumpController(false);
    %>
    <%
        if (request.getParameter("buttonName") != null) {
            if(request.getParameter("buttonName") == "Pump is On!") {
                pc.setPumpStatus(true);
            } else {
                pc.setPumpStatus(false);
            }
        }

    %>

    <form name="overrideForm" method="get">
        <input type="hidden" name="buttonName"/>
        <input type="button" name="override" value="Override"
            onclick="changeState(this.value)"/>
        <input type="button" name="cancel" value="Cancel"
            onclick="changeState(this.value)" />
    </form>
    <div id="pumpState" style="visibility: hidden">
        <label style="background-color: green;">Pump On!</label>
    </div>
    <script language="JavaScript">
        function changeState(val) {
            if (val == 'Override') {
                document.overrideForm.buttonName.value = "Pump is On!";
                overrideForm.submit();
                document.getElementById('pumpState').setAttribute('style',
                        'visibility:visible');

            }
            else {
                document.overrideForm.buttonName.value = "Pump is Off!";
                overrideForm.submit();
                document.getElementById('pumpState').setAttribute('style',
                        'visibility:hidden');
            }
        }
    </script>
</body>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.