Modify form layout upon selection of a specific radio button

Hey there! I'm a student currently diving into the world of JavaScript, CSS, and HTML. However, I've encountered a little problem while working on an exercise that involves using Bootstrap.

function ShowForm(formId){
    document.getElementById("form1").style.display = "none";
            document.getElementById("form2").style.display = "none"; 
    document.getElementById(formId).style.display = "block"; 
}
<!doctype html>
<html lang="en">
  <head>
    <title>Registration Form</title>
  </head>
  <body>
   <div class="container">
     <h1>Registration Form</h1>
      <div class="form-check form-check-inline">
        <input class="form-check-input" type="radio" name="inlineRadioOptions" value=1 onclick="ShowForm('form1');" >
        <label class="form-check-label" for="inlineRadio1">Individual</label>
      </div>
       <div class="form-check form-check-inline">
        <input class="form-check-input" type="radio" name="inlineRadioOptions" onclick="ShowForm('form2'); " value=2>
        <label class="form-check-label" for="inlineRadio2">Company</label>
      </div>
      <form id="form1" class="row g-3" value=1>
        <div class="col-md-6">
          <label for="inputEmail4" class="form-label">Email</label>
          <input type="email" class="form-control" id="inputEmail4">
        </div>
        <div class="col-md-6">
          <label for="inputPassword4" class="form-label">Password</label>
          <input type="password" class="form-control" id="inputPassword4">
        </div>
    </form>

    <form id="form2" type="hidden" class="row g-3" style="display:none;" value=2>
      <div class="col-md-6">
        <label for="inputEmail4" class="form-label">SomeLabel</label>
        <input type="email" class="form-control" id="inputEmail4">
      </div>
    </form>
    </div>
  </body>
</html>

Can anyone help me understand why clicking the radio button changes the form layout? Thanks a bunch!

Answer №1

There are already two distinct forms set up for you. By clicking on a radio input (where exactly is it located outside the forms?), a function will trigger to toggle between displaying the forms.

Outcome: One form is hidden while the other one is displayed, each with different quantities of input fields.

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

Execute a bash script from a local URL using fetch

I'm curious about converting a curl command into a bash script with input variables using fetch. It works perfectly in the console: curl -s http://localhost:3001/ident.sh | bash /dev/stdin x627306090abab3a6e1400e9345bc60c78a8bef57 2 10194897676576 ...

After a brief delay, I aim to eliminate a className or restart the class animation when a certain condition is satisfied

Objective: My goal is to create a feature where the price number highlights with a color for a brief moment when there is a price change using toggleClassName. Challenge: The issue arises when the iteration is UP UP or DOWN DOWN, as the element already ha ...

Experiencing an issue with the Web Crypto API in NextJS due to receiving the error message "crypto is not defined."

I was wondering if NextJS supports the use of the web crypto API. Recently, I attempted to utilize it by writing the following code: crypto.subtle.digest('SHA-256', data) However, I encountered an error message that said: ReferenceError: crypto ...

EJS not displaying object values properly

I'm currently in the process of setting up a blog and I want to create a page that displays the titles of all the articles I've written. For example: List of Articles: * Title: Article 1 * Title: Article 2 * Title: Article 3 Below is my Schem ...

Differences Between APP_INITIALIZER and platformBrowserDynamic with provide

I've discovered two different approaches for delaying an Angular bootstrap until a Promise or Observable is resolved. One method involves using APP_INITIALIZER: { provide: APP_INITIALIZER, useFactory: (configService: ConfigurationService) => ( ...

over line up text align on the baseline with hr

I'm looking to make sure the text is positioned just above the hr tag, similar to how the logout button appears with bootstrap. This is the desired outcome: https://i.sstatic.net/gIl1b.png Here's the code I have using bootstrap : <di ...

The background image is not appearing on the div as expected

I've been attempting to create a div and set a background image for it using jQuery, but I seem to be facing issues. When I try setting the background color to white, it works fine. Here's the code snippet: function appendToDom(poster) { ...

Ensuring thoroughness in validation without the use of specific text strings

Implementing the assignment or assertion of never at the end of a function is a strategy commonly used in Typescript to ensure exhaustive checks at compile time. To enable the compiler to recognize this, explicit strings are needed for it to check against ...

Using Material UI's onClose as an alternative to disableBackdropClick

I currently have a dialogue box displayed on my webpage. <Dialog open={open} data-testid="myTestDialog" disableEscapeKeyDown={true} disableBackdropClick={true} > After visiting the documentation at https://material-ui.c ...

Instructions for instructing Codeception to finalize the selection from a dropdown list without the need to click on a submit button

I am facing an issue where I am able to select an element from a drop down list in codeception, but it is not being displayed as selected in the box. I believe the select operation is not completing properly. Since there is no submit button available, I at ...

"Can you share how to send an array of integers from a Jade URL to an Express.js route

I am currently working on creating an array of integers in JavaScript using the Jade template engine. My goal is to send this array to an Express.js route when a button is clicked. I have attempted the following code: Jade File: //Passing the ID to fu ...

Changing the URL dynamically based on user interaction with jQueryLet's leverage the power of

In continuation to my previous post, I am looking to dynamically change a URL based on the selected language. For example, if the current URL is href="../folder/Languages/English/test/test.html, clicking or selecting another language should update it to: h ...

Tips for customizing the appearance of date circles and text in Vue V-Calendar.io

On v-calendar.io, there is a demo showcasing the correct display where the date "2018-01-01" has a red background and dark text: However, my display does not match that. I have included Vue.js and v-calendar through CDN, and the page is formatted in HTML ...

Scripted AngularJS directive

Essentially, the directive I have defined as sample.js is: app.directive('myDirective', function() { return { restrict: 'E', scope: { info: '=' }, templateUrl: 'link-to-sam ...

Concealing an element using Jquery's Ajax upon successful request

I want to make a button disappear after successfully uploading an image file when clicked. Here is the code I am using: $(document).on('click', '.upload-image-click', function() { var token = $('input[name="csr"]&apo ...

Guide on retrieving HTML content from a URL and showing it in a div

I'm trying to retrieve the content of a URL and display it within a DIV element, but I'm struggling to achieve the desired result. Below is the code I'm using: index.js fetch('https://github.com/') .then(res => res.text()) ...

Once the form has been submitted, proceed to open a new page following processing

Trying to remove an entry or offer from the database and then return to the page with all entries/offers. Attempted using Javascript, but it successfully deletes the item without redirecting to the overview page. Is this the correct approach with Javascri ...

Looking for giphy link within a v-for loop (Vue.js)

I am fetching a list of movie characters from my backend using axios and rendering them in Bootstrap cards. My objective is to search for the character's name on Giphy and use the obtained URL as the image source for each card. However, when I attemp ...

choosing between different options within Angular reactive forms

I am attempting to create a select element with one option for each item in my classes array. Here is the TypeScript file: @Component({ selector: 'app-create-deck', templateUrl: './create-deck.component.html', styleUrls: [' ...

The JavaScript function getSelection is malfunctioning, whereas getElementById is functioning perfectly

I am encountering a peculiar situation while trying to input text into a textbox using a JavaScript command. The CSS locator does not seem to update the text, whereas the ID locator is able to do so. URL: Below are screenshots of the browser console disp ...