Tips for showing a different div in the chat window after submitting the form

My index html file features a chat window designed like this:

https://i.sstatic.net/PPGoy.png

Below the submit button is an area to input text. How can I hide or disable this section and enable it only after the form is filled and the submit button is clicked? I attempted to hide the div class but encountered an error.

Here is the relevant HTML code:

<html>

   <head>
      <title>Chatbot</title>
      <!--Let browser know website is optimized for mobile-->
      <meta name="viewport" content="width=device-width, initial-scale=1.0" />

      <!--Import Google Icon Font-->
      <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
      <link href="https://fonts.googleapis.com/css?family=Raleway:500&display=swap" rel="stylesheet">
   
   ...
   

Answer №1

To tackle this issue, start by identifying the specific textarea element that you wish to hide/disable using

const textarea = document.querySelector("#userInput");
.

Once you have successfully targeted it, you can disable it with: textarea.disabled = true; (this will still display the element on the page but prevent any interaction with it).

Alternatively, you can opt to completely hide it with textarea.style.display = "none";.

In order to re-enable/display the textarea in your validateForm function after form submission, use the following code snippet:

    function validateForm() {
              if (!validateName() || !validatePhone() || !validateEmail()) {
                alert("Form not submitted"); //Validation Message
                return false;
              } else {
                submitted = true;
                form.style.display = "none";

                textarea.disabled = false;
                textarea.style.display = "inline-block";

                return true;
              }
            }

Full implementation:

    const textarea = document.querySelector("#userInput"); //select the target textarea element
    textarea.disabled = true; //disable it
    textarea.style.display = "none"; //or hide it completely

    function validateForm() {
      if (!validateName() || !validatePhone() || !validateEmail()) {
        alert("Form not submitted"); //Validation Message
        return false;
      } else {
        submitted = true;
        form.style.display = "none";
        textarea.disabled = false; //re-enable it
        textarea.style.display = "inline-block"; //or display it again
        return true;
      }
    }

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

Implementing iOS scrollbars as a solution for the Bootstrap 4 Carousel Bug that triggers extra swipes with just a click or tap

The issue & environment Utilizing Bootstrap 4 via CDN, a problematic scenario has arisen with the Carousel feature on iOS devices. An identified bug persists in this aspect of Bootstrap, acknowledged with a potential resolution available through githu ...

How can you use three.js to easily create a cylinder with a slice removed from it?

Can someone guide me on creating a 3D model of a cylinder with a slice cut out using three.js? Something similar to this: Image Your input is highly valued. Thank you. ...

Embedding a Three.JS renderer within a canvas or div element

I've been attempting to embed a 3D model viewer in a responsive layout along with other content like text. Initially, I used window.innerWidth and window.innerHeight for setting the renderer size, but later switched to .clientWidth and .clientHeight t ...

Tips for transferring a dataTable from C# code behind to jQuery

I am trying to pass a string as a table of data from C# code behind to jQuery using two functions: C# [System.Web.Services.WebMethod(EnableSession = true)] public static List<ListItem> GetImageArray(string AccNo) { string result = string.Empty; ...

IE11 is unable to display the background image

I am attempting to create a process roadmap by using background images on list items. The background-image on the list item is not showing up in IE11 (also in all versions of IE10, 9, etc). CSS CODE body{padding: 50px 0;} .status-line { width: 80%; ...

Whenever a specific item within a list-group is clicked, I aim to display additional information pertaining to that particular selection

At the moment, the page is displaying the titles of an array stored within a JSON string. My objective is to reveal the remaining details in that array upon clicking on the title. This can be achieved by showcasing the additional information either in anot ...

numerous items sharing identical key values

I am dealing with an array of objects: [object, object, object, object, object] and I need to assign a unique key to each object based on its title: {test:object, tester:object, foo:object, bar:object, test:object} This way, instead of accessing the ob ...

Utilize CodeIgniter to input information into the database

I am encountering an issue with inserting data into a database. Instead of successfully adding the data, it just displays the input on the URL bar after submitting the form. The view input_data.php can be found at: C:\wamp\www\CodeIgniter&b ...

Content and footer being covered by the sidebar

I have an illustration here to help explain my issue. The problem I am facing is that the Sidebar is overlapping both my Content and Footer when the content consists of only small items. In my _layout file, I'm referencing the sidebar like thi ...

I am unable to establish a connection with the database following the utilization of AJAX

Recently, I encountered an issue while attempting to delete a comment on my website and in the database. Although the comment was successfully removed from the website upon clicking the delete button, the deletion did not reflect in the database. Even afte ...

Tips for placing text on top of an image within a <p> element

I am grappling with a situation where I have a div containing text within <p> tags, and also an accompanying PNG image. My goal is to position the image to the left of the div so that it overlaps with the text. Despite my attempts at utilizing z-inde ...

Make sure to incorporate certain node_modules folders within Babel 7

My issue involves a dependency located in the node_modules directory that requires compilation through Babel. Despite upgrading my stack, I am unable to get Babel to compile the dependency. Current versions: @babel/core 7.5.4 webpack 2.7.0 Here is my w ...

The most recent axios request yielded a null response

I needed to retrieve the current weather conditions of a specific location, so I decided to utilize two different APIs. The first one being Mapbox, which helped me convert the place name to geo-coordinates. The second API I used was Accuweather. Additional ...

Visible images remain unloaded by Lazy Load

Currently, I am implementing lazyload functionality on my website to only load images that are visible. This is necessary because some content is hidden when viewed on smaller screens using display:none. The issue I am facing is that lazyload only starts ...

Identifying when the mouse hovers over a hidden element

Is there a way to make events trigger for <mark> elements under a <textarea>? I've tried adding mouseover listeners, but they don't seem to work because of the <textarea>. I need the <text-area> to function normally, so u ...

The attempt to log in using AJAX and PHP was unsuccessful

Why does the output always show a false alert even though the email and password match those in the database? PHP: <?php include 'db.php'; $email = trim($_POST['email']); $password = trim($_POST['password'] ...

What could be causing the file resumeData.json to not load correctly on GitHub pages after deployment?

After trying out this specific tutorial for deploying my personal website template found on GitHub to GitHub pages, I encountered an issue with the loading of information from public/resumeData.json. My personal page can be accessed at: The master branch ...

Clicking on text will open a popup div using HTML and CSS

I am looking to create a popup div instead of a popup window for my 'About' picture/page with the current button. Here is an example: ...

Form for sending mail using custom AJAX capabilities

Here is the HTML form code I have: <form id="main-contact-form" name="contact-form"> <div class="row wow fadeInUp" data-wow-duration="1000ms" data-wow-delay="300ms"> <div class="col-sm-6"> ...

Creating a pull-up toolbar with just HTML and CSS for an Android browser

I need to create a draggable toolbar on my mobile webapp that can reveal content beneath it. I want to achieve this using just HTML/CSS, without relying on touch/scroll events or libraries. To do this, I'm overlaying a scrolling element on top of the ...