Is it possible for me to overlap a text over hidden text, and if the hidden text becomes visible through JavaScript, my text will shift to the right of the now visible hidden text?

I'm currently working on a website for a company that requires users to complete all the information before proceeding.

To achieve this, I created a form with the following code:

    <form action="Owners Infoback.php"  onsubmit="return validateForm()"  method="post" name="enquiry" id="" class="form-body-02">
    <ul>
        <li style="overflow:hidden;">
          <label for="Name" class="l1">1. Name of owner:<br />
         <p>(If more than one separate using comma.</br> Eg. A,B,C )<br /></p></label>
         <div id="nameOfOwnerError" style="visibility:hidden;color:red; display:inline; margin-left:20px;">*</div>
         <input name="Name_of_owner" type="text" class="textarea-bk-02" id=""  value="<?php echo "{$row[0]}";?>" style="border:none; width:330px; margin-left:14px; margin-top:15px; height:20px;"/>

        </li>

        <li>
          <label for="Name" class="l1">2. Name of company:<br /><p>(Enter name registered)</p></label>
          <div id="nameOfOwnerCompany" style="visibility:hidden;color:red; display:inline; margin-left:20px;">*</div>
          <input name="Name_of_company_registered" type="text" class="textarea-bk-02" id=""  value="<?php echo "{$row[1]}";?>" style="border:none; width:330px; margin-left:10px; margin-top:13px; height:20px;"/>
        </li>

        <li>
          <label for="Name" class="l1">3. Address:<p>(Write your own manufacturer address)</p></label>
          <div id="nameOfOwnerAddress"style="visibility:hidden;color:red; display:inline; margin-left:20px;">*</div>
          <input name="Owner_address" type="text" class="textarea-bk-02" id=""  value="<?php echo "{$row[2]}";?>" style="border:none; width:330px; height:20px; margin-left:13px; margin-top:13px;"/>
        </li>

        ...
  </form>

and in the header section, I implemented the following JavaScript code:

     <script>
     function validateForm()
{
var y=true;
var x=document.forms["enquiry"]["Name_of_owner"].value;
if (x==null || x=="")
  {
    document.getElementById("nameOfOwnerError").style.visibility="visible";  
    document.getElementById("nameOfOwnerError1").style.visibility="visible"; 
    y= false;
  }
  else
  { document.getElementById("nameOfOwnerError").style.visibility="hidden";
    document.getElementById("nameOfOwnerError1").style.visibility="hidden";
  }

  ...
}
</script>

When running the script, I encountered an issue where empty fields were leaving gaps in the red text. It is not displaying a continuous error message for each field. How can I fix this and ensure consistent error messaging?

As a new user, I apologize for the lack of images showing the issue. In the screenshot provided, you can see that only certain fields are being highlighted in red when left empty, causing gaps in the error messages. How do I eliminate these blanks spaces between the error messages?

Answer №1

When looking to show an element, instead of:

.style.visibility="visible"; 

You can try:

.style.display = ''; 

And when trying to hide an element, instead of:

.style.visibility="hidden"; 

You can use:

.style.display = 'none'; 

Answer №2

Check out this jsfiddle link: http://jsfiddle.net/rakesh_katti/cLjAN/

Please review to see if it meets your expectations.

I noticed that the php script was accidentally placed inside the value attribute of each input tag, and the border:none property was causing the input borders to disappear. I made those corrections. Also, it seems like you used a div element with a red asterisk as a marker for required fields.

Do you think I understood everything correctly?

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

Error with Ant Design Autocomplete functionality when searching for a number

I am currently using ant design to develop a more advanced autocomplete component that will display data from multiple columns. In this particular scenario, I have two columns named tax_id and legal_name that users can search by. Everything works smoothly ...

Is there a way to efficiently update specific child components when receiving data from websockets, without having to update each child individually?

Currently, my frontend requires updated data every 2 seconds. The process involves the frontend sending an init message to the backend over a websocket. Upon receiving this message, the backend initiates an interval to send the required data every 2 second ...

State loss occurs when moving to a different page using next/link

Currently, I am working on a library application with Next.js. Within this project, there are two main pages: BooksPage, which displays a list of all books, and BookPage, where detailed information about a specific book is shown. The components involved in ...

Extract information from a URL using Regular Expressions

On my page, I have a list of blog post links: <ul class="postlist"> <li><a href="http://someblog.it/blogpost/7/-----.aspx">Post One</a></li> <li><a href="http://someblog.it/blogpost/32/----------.aspx">Post Two< ...

What is the best way to link this interval service with a view component?

Exploring the AngularJS documentation for $interval, I came across an interesting example demonstrating how to utilize $interval in a controller to create a user-friendly timer in a view. The official example code can be found on the angularJS documentatio ...

The Webix component is experiencing a lack of refreshment

function refresh_group_items(){ //console.log("calling1"); window.setTimeout(function(){ $$("cfg").reconstruct() }, 3000); } $.ajax({ type: "POST", xhrFields:{ withCredentials: true }, beforeSend: function(reque ...

Language translation API specifically designed to convert text content excluding any HTML formatting

I have a dilemma with translating text content in an HTML file into multiple languages based on user input. To accomplish this, I am utilizing the Microsoft Translator AJAX interface. The structure of my HTML file looks something like this; <h1>< ...

Using React to dynamically assign a backgroundImage based on a JSON response

I am having an issue with retrieving data from my Wordpress API and displaying it in my react app. Specifically, I am struggling to set the post's featured image as a background-image for an element. Here is an example of the JSON response: { "id" ...

Using a variable with the :contains selector

function checkAndUpdateStatus(newName) { $('#myTable').children('tr').remove(":contains('" + newName + "')"); }; The function above is attempting to remove table rows in 'myTable' containing a string matching the ...

Different ways to tag users with the "@" symbol in Django

I've been diving into a project on django that has similarities to Instagram and Twitter. One crucial function it needs is the ability to mention users using "@" in text fields. After some research, I've come up empty-handed, except for libraries ...

Is it possible for me to listen to an AngularJS event using regular JavaScript, outside of the Angular framework?

Is it possible to listen to an event triggered in AngularJS using regular JS (outside of Angular)? I have a scenario where an event is being emitted using RxJS in Angular 2. Can I observe that event from pure JS? Here's some example pseudo code: imp ...

Error in Material UI when using the select component

CustomComponent.js:98 UI Error: The value undefined provided for the selection is out of range. Please make sure to select a value that matches one of the available options or ''. The available options are: `All`, `Software Development`, `Qualit ...

Issues with Pageinit and Ready Event Timings

Check out this fiddle where I am experiencing an issue related to pageinit and ready events In the fiddle, everything functions properly using onLoad and onDOMready. This includes: The subject listings are loaded correctly with a popup displaying module ...

Retrieve the latency of the interaction.reply() method

While there have been many inquiries regarding how to create a ping command for a discord.js bot, my question stands out because I am attempting to develop this command for interaction rather than message. I attempted utilizing Date.now() - interaction.cre ...

Can Googlebot detect changes made to an HTML <title> tag using JavaScript?

Within my website, I have a search engine that operates using ajax technology. My goal is to assign a unique <title> for every search request made. This involves modifying the title each time I receive a response from the ajax feature. I am wonderin ...

Displaying a collection of nested objects in AngularRendering a group

Is there a way to render an object of objects in Angular without converting it into an array or similar structure? I have a large object of objects and I want to avoid multiple iterations through object-to-array conversions just to loop through the array i ...

Disabling a Field in Angular While Preserving its Value

Hey there, late night folks! I have a quick question about Angular. I'm working with a form that includes a specific field where I set the value using patchValue, but I also need to disable this field. The issue is that after disabling it, the value i ...

Errors related to missing RxJS operators are occurring in the browser, but are not showing up in Visual Studio

Recently, I encountered a peculiar problem with my Angular4 project, which is managed under Angular-CLI and utilizes the RxJS library. Upon updating the RxJS library to version 5.5.2, the project started experiencing issues with Observable operators. The s ...

jQuery functions failing to target dynamically generated elements

I've encountered an issue while attempting to implement my jQuery functions on dynamically created content using the .on API from jQuery. The main objective of the code is to display a specific set of options only when a user hovers over the ".feed_po ...

What steps can I take to guarantee that both images and text adapt well to different screen sizes?

Is there a way I can organize my website to display 3 movies per row with the text centered relative to the image? Here is how it currently looks (the red box is just for reference, please ignore): https://i.stack.imgur.com/w2pgN.jpg Also, when I resize m ...