Tips for concealing labels until the submit button is activated

I am currently handling a project involving a Spring Controller and JSP. Within a JSP page, I have included a button labeled Process. Upon clicking this button, two radio buttons are displayed below it along with a Submit button.

After tapping the Submit button, assuming everything goes smoothly, the following data is exhibited (which will be retrieved from the controller):

Success= true 
Error= none

However, upon inspecting my layout on the browser via the provided jsfiddle link, the form appears as follows:

Process

Success= 
Error= 

This indicates that the form initially displays the "Process" button at the top, followed by empty "Success" and "Error" labels since no values have been supplied yet from the controller. This presentation may appear awkward to users.

Hence, my aim is to either conceal the "Success" and "Error" labels upon page load or when the Process button is clicked. These labels should only become visible once the submit button is pressed, providing their relevant values for "Success" and "Error" based on the controller's output.

Is it feasible to achieve this using jQuery? To clarify, I intend to hide these labels until the submit button is triggered...

Alternatively, I welcome suggestions for a more effective design approach to display the Success and Error labels in accordance with my objective.

Answer №1

In my opinion, JavaScript may not be necessary for this task since it appears that the form submission is handled by the backend. In JSP, you could simply perform a check like:

<% if (success.length > 0 || error.length > 0) { %>
    <!-- display success / error labels here -->
<% } %>

However, if you prefer to use JavaScript, you can try something along these lines:

if (!$("#success-value").text().length && !$("#error-value").text().length) {
    // hide the labels
}

Check out this example on jsfiddle

Answer №2

If you're interested, feel free to check out my fiddle.

Feel free to visit jsfiddle.net/4Nmqk/26

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

Using Leaflet to beautify categorical json information

As a beginner in coding, I must apologize if a similar question has already been asked. I've spent days searching but haven't found the right combination of terms to find examples for my scenario. I am exploring various small use cases of differ ...

Troubleshooting Issue with Node.js and Postman: Error encountered while attempting to

Consider the following code snippet: const fs = require('fs'); const express = require('express'); const app = express(); const bodyParser = require('body-parser') // using middleware app.use(express.json()); app.use(bodyPar ...

Is there a way to retrieve SQL information through an API and then incorporate that data into react-native-svg charts? I have an API that contains data I would like to retrieve and showcase

I am utilizing an API to retrieve data, which includes the execution of SQL queries. The API is responsible for fetching data and running these queries. I am looking for a way to replace the static data in my charts with dynamic data fetched from the API. ...

Stylesheets per module in Angular 2

For my website design, I've decided to adopt a modular structure using sass. To ensure consistency throughout the module, instead of defining stylesheets at the component level, I plan to define them at the module level and import them into each compo ...

Implementing a CheckBox Overlay within a JQuery Dialog

Using the JQuery dialog plugin, I have created a custom dialog with the following structure: <div id="initialQuestions" title="Please complete the following"> [Questions] </div> <div id="checkField" style="visibility:hidden; z-index:1001" ...

Use jQuery to update the field without affecting the observable

Greetings to the wonderful stackoverflow community! I recently delved into using knockout just a few days back. Currently, I am utilizing it to create a dynamic menu builder for a CMS project that I'm deeply engrossed in. If you'd like to take ...

Ways to launch numerous URLs in express.js

I am currently developing a service similar to a URL shortener. While a typical URL shortener redirects the user to one page, my service needs to open multiple URLs simultaneously. When a user clicks on a link from my website, I want it to open multiple l ...

Linking Redux to the highest level of my application is not functioning as expected

I have been attempting to troubleshoot this code for quite some time now, but I am struggling to identify the issue at hand. My main goal is to establish a connection between my top-level application and the redux store. However, every time I try, the stor ...

In PHP, it is essential to always complete the necessary information in form validation

I've been working on implementing JavaScript form validation, but I seem to be having trouble with testing for empty fields in the form. Whenever I submit a fully filled out form, it keeps asking me to fill in the blank fields. Here is the code I hav ...

What is the best way to position the sign-in modal form on the top right corner of my website?

Hey there, I'm facing a bit of an issue and can't seem to figure out what went wrong. Recently, I inserted a Bootstrap Sign In modal in my HTML file. Here's the code: <div class="text-center"> <a href="" class ...

Struggling with jQuery fadeIn and fadeOut in IE8?

I am struggling to understand why my fadeIn, fadeOut, and corner() functions are not working in IE8 on my website at . They were functioning properly before, but now they seem to be broken. Can anyone pinpoint the issue causing this problem? If you click ...

Is it possible for Vue to retrieve refs on mounted during nextTick following the dynamic import of the component?

Utilizing Nuxt js and Element UI, I have dynamically imported Element UI plugins in the plugins folder. export default () => { Vue.component("ElForm", () => import("element-ui/lib/form")); Vue.component("ElFormItem", ...

Is there a way to horizontally navigate a pallet using Next and Prev buttons?

As someone new to development, I am looking for a way to scroll my question pallet up and down based on the question number when I click next and previous buttons. In my pallet div, there are over 200 questions which are dynamically generated. However, th ...

Exploring the process of creating a interactive rectangular border on an image with JavaScript

I'm currently working on a project that requires me to draw multiple bounding boxes interactively within an image displayed on a web browser. After drawing the bounding boxes, I will need to extract their coordinates. Are there any suggestions for a J ...

How can I stop my browser from recalling text field data?

Similar Question: Is there a W3C compliant method to disable autocomplete in an HTML form? How can I stop a browser from remembering the text field's content? The issue arises when the field has a value like 100, followed by a currency symbol suc ...

Retrieving chosen row data in Angular 6 Material Table

I am attempting to send the value of a selected row from one component to another upon clicking a button. However, in this particular example, I'm unsure where to obtain the selected row values and how to pass them on button click. After that, routing ...

"Utilizing jQuery to target and manipulate the outer HTML content

Picture this scenario: <div id="xxx"><p>Hello World</p></div> When the .html function is called like this: $("#xxx").html(); The output will be: <p>Hello World</p> However, I actually need to retrieve: <div id= ...

Ways to generate a unique link for every value in an option tag dynamically?

I'm currently working on a form that allows customers to buy an online service. Within the form, there's a dropdown list featuring 'select' and 'option' tags. This dropdown menu lets users pick a billing cycle (6 months, 1 ...

Manage shared nested modules across different modules in Vuex without redundancy

In my Vue.js application, I am using Vuex as the state manager. To ensure that certain states are shared across different components, I have created a nested state containing all the common information. This allows me to import it into multiple modules. F ...

"Viewed By" aspect of Facebook communities

I'm working on implementing a feature that shows when a post has been seen, similar to Facebook groups, using JS and PHP. I've been able to track the number of times a post has been seen through scrolling actions, but now I want to determine if u ...