Reducing the size of a Form Fieldset text once an option has been selected

I’m brand new to the world of Javascript and Jquery and I'm currently working on designing a unique questionnaire-style webpage.

My goal is to pose a question, then once an answer has been selected, shrink the text and display the next question in its normal size.

I’ve managed to get most of the page to function properly in terms of showing and hiding elements. However, I’m facing difficulty in reducing the initial question text size. Despite reading various tutorials and examples, I haven’t been able to find a solution that works. Any guidance would be greatly appreciated.

Thank you in advance!

Here is the HTML snippet I’m working with:

<form>
   <fieldset class="form1">
      <p>What problem is the customer experiencing?</p>
      <input type="radio" name="issue" value="o - issue1" onClick="getIssueVar()">issue1<br/>
      <input type="radio" name="issue" value="o - issue2" onClick="getIssueVar()">issue2<br/>
      <input type="radio" name="issue" value="o - issue3" onClick="getIssueVar()">issue3<br/>
      <input type="radio" name="issue" value="o - issue4" onClick="getIssueVar()">issue4<br/>
   </fieldset>
</form>
<br/>

Below is the Javascript snippet:

function getIssueVar() {
   var xissue = document.getElementById("testform");
   var issuetext = "";
   var iissue;
   for (iissue = 0; iissue < xissue.length; iissue++) {
      if (xissue[iissue].checked) {
         issuetext = xissue[iissue].value;
         break;
      }
    }
   document.getElementById("faultissue").innerHTML = issuetext;
   $(".form2").show();
   $(".form1").css('font-size', '10px');
}

I’ve also defined my CSS:

.form1
{
font-size:14px;
}

My plan was to use Javascript/jQuery to adjust the font size once a radio button is clicked. However, it doesn’t seem to be working as expected. What am I missing here?

Answer №1

Learn HTML Here

<form>
   <fieldset class="form1">
      <p>What is the customer's issue?</p>
      <input type="radio" name="problem" value="A - problem1" onClick="getIssueVariable()" class="testform">problem1<br/>
      <input type="radio" name="problem" value="A - problem2" onClick="getIssueVariable()" class="testform">problem2<br/>
      <input type="radio" name="problem" value="A - problem3" onClick="getIssueVariable()" class="testform">problem3<br/>
      <input type="radio" name="problem" value="A - problem4" onClick="getIssueVariable()" class="testform">problem4<br/>
   </fieldset>
</form>  

<div id="issueproblem"></div>  

JAVASCRIPT

function getIssueVariable() {
    debugger
   var xproblem = document.getElementsByClassName("testform");
   var problemtext = "";
   var iproblem;
   for (iproblem = 0; iproblem < xproblem.length ;iproblem++) {
      if (xproblem[iproblem].checked) {
         problemtext=xproblem[iproblem].value;
         break;
      }
    }
   document.getElementById("issueproblem").innerHTML = problemtext;
   $(".form2").show();
   $(".form1").css('font-size', '10px');
}  

Check out the DEMO
In your code, it appears that the testform class is missing from the radio button tag. Also, an element with the id issueproblem is missing as well.

Answer №2

Looking for a solution using jQuery? Check out this delegated on() click approach.

<form>
   <fieldset class="form1">
      <p>Is the customer experiencing any problems?</p>
      <input type="radio" name="issue" value="o - issue1" >issue1
      <br>
      <input type="radio" name="issue" value="o - issue2" >issue2
      <br>
      <input type="radio" name="issue" value="o - issue3" >issue3
      <br>
      <input type="radio" name="issue" value="o - issue4" >issue4
   </fieldset>
</form>
.minimize {
    font-size: 0.5em;
}
$('fieldset').on('click', 'input[type="radio"]', function() {
    $radio = $(this);
    $fieldset = $radio.parent();
    $fieldset.addClass('minimize');
});

Check out the code in action on jsFiddle: http://jsfiddle.net/w4L1g2dc/

If you prefer, you can directly set the CSS instead of adding a class.

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

The API designed to accept JSON data via a POST request is receiving a different data type than expected

I have a task to develop an API that receives JSON data in NODE.JS via the POST method. To simplify request management, I utilize Express and BodyParser library to handle the body of POST requests. The data is structured in a JavaScript object like this: ...

Tips for nesting an anchor tag within another tag

After reviewing various inquiries on this platform, it has been commonly believed that embedding an anchor tag inside another anchor tag is not achievable. However, I recently stumbled upon a website that successfully accomplishes this and I am curious to ...

Refresh the homepage of a website using React Router by clicking on the site's logo from within the Home component

In most cases, when you click on a website's logo while on the homepage, it typically reloads the page. However, with React, clicking on the logo while already on the Home component does not trigger a reload. Is there a way to work around this issue? ...

The process of how screen readers interpret HTML elements

It is important to understand that screen readers not only read the content within elements and tags, but also the elements or tags themselves. For example: <button class="class-of-the-button">Text inside</button> When read by a screen reader ...

Ways to implement the React.FC<props> type with flexibility for children as either a React node or a function

I'm working on a sample component that has specific requirements. import React, { FC, ReactNode, useMemo } from "react"; import PropTypes from "prop-types"; type Props = { children: ((x: number) => ReactNode) | ReactNode; }; const Comp: FC< ...

Unable to utilize jQuery to select and copy the value of an HTML element

Is it possible to transfer a value from one div to an input field? I attempted to show the selected value, but it keeps displaying undefined. Any ideas why? <div class="thumbnail" id="thumbnail2"> <div class="book author"> Author One < ...

"Incorporating a hyperlink into a newly added table row with the help

When utilizing jQuery, I am able to dynamically add rows to a table with each row containing an anchor tag. However, when attempting to populate the anchor tags with links using jQuery, the links do not appear as expected. Strangely enough, the other data ...

Activate month input programmatically

Having an issue trying to open a month popup using jQuery trigger. I have a button and an input of type month, but when the button is clicked, the popup does not open as expected. You can find the fiddle for this question here. $(document).ready(functio ...

Adjust and position any svg element to fit the entire viewport

Forgive me for being just another person to ask this question. Despite my efforts, I have yet to find a solution. I am trying to resize "any" svg to fit the entire viewport, centered. Take for example this svg element: <svg baseProfile="full& ...

Assist me with Twitter

Seeking assistance with a coding issue related to displaying Twitter posts on a website. I have found a code snippet that accomplishes this: //Scrolling of tweets in the footer $(function () { var tweetVP = $("#footerTweetsViewport"); arrTweetNav ...

What is the proper way to access object properties in EJS?

My server has an express API to retrieve food items and I want to display their names on my ejs index file. In order to fetch the data, I have the following code in my server.js file: app.get('/', async (req, res) => { try { fetch ...

What is the process for developing an interface adapter using TypeScript?

I need to update the client JSON with my own JSON data Client JSON: interface Cols { displayName: string; } { cols:[ { displayName: 'abc'; } ] } My JSON: interface Cols { label: string; } { cols:[ { label:&a ...

Explore button that gradually decreases max-height

I have a "Show More" button that expands a div by removing the css attribute max-height, but I want to add an animation similar to jQuery's slideToggle() function to smoothly reveal the rest of the content. This is the code I am using: <div id="P ...

Having trouble with errors when adding onClick prop conditionally in React and TypeScript

I need to dynamically add an onClick function to my TypeScript React component conditionally: <div onClick={(!disabled && onClick) ?? undefined}>{children}</div> However, I encounter the following error message: Type 'false | (() ...

Why isn't my Vue2 data updating in the HTML?

Starting my journey with Vue, I have been finding my way through the documentation and seeking support from the Vue community on Stack Overflow. Slowly but steadily, I am gaining a better understanding of how to create more complex components. The issue I ...

What is preventing the use of this promise syntax for sending expressions?

Typically, when using Promise syntax, the following code snippets will result in the same outcome: // This is Syntax A - it works properly getUser(id).then((user) => console.log(user) // Syntax B - also works fine getUser(id).then(console.log) However ...

Creating a WasmModuleBuilder in V8 that enables functions to return multiple values

I'm currently working on creating a wasm function using WasmModuleBuilder from V8: var builder = new WasmModuleBuilder(); builder.addMemory(5, 5, false); builder.addFunction("func", {params: [125,125], results: [125,125]}); builder.functions[0].addBo ...

Unable to maintain the height of a div at 100% as it keeps reverting back to 0px

I'm having trouble setting the height of the individual parent columns (and their children) to 100% because for some reason, the div height keeps resetting to 0. The first column contains two child boxes that should each take up 50% of the page heigh ...

Distinguishing between creating controllers in AngularJS

I am a beginner in the world of AngularJS and I have come across two different examples when it comes to creating a controller. However, the one that is more commonly used doesn't seem to be working for me. The problem with the first example is that ...

Why isn't the AngularJS injected view resizing to fit the container?

As a novice delving into a project in the MEAN stack, I'm encountering inconsistent HTML previews. When I view it independently versus running it from the project, the display varies. Here's the intended appearance (in standalone preview): imgu ...