Tips for adjusting dimensions dynamically through leveling

I encountered some issues while working with input fields. Whenever I type text in one input field, the text seems to appear in another field as well. The width and height of the second text field do not adjust dynamically like in the provided image on the demo site.

Check out my Demo Site

The default width and height are as shown below:

https://i.sstatic.net/QB1Jd.jpg

https://i.sstatic.net/ypr6g.jpg

https://i.sstatic.net/QMZ90.jpg

However, I want the output to resemble the design on this desired output link: Desired Output Link

https://i.sstatic.net/qkfik.jpg

https://i.sstatic.net/SjJ3z.jpg

In order to achieve the desired output, the input should be structured similarly to these examples on the demo site:

https://i.sstatic.net/kNU9N.jpg

One issue I faced is that the height is displayed above the box instead of on the left or right side of it.

Another problem arises when there is an inner hole within the box, which I have not accounted for in my design.

Lastly, there is an issue where the leveling end arrow does not get added to the leveling line. Here is a snippet of my code:

For input text:

<div class="text_input1">
    <p class="label1"> Text 1 <input class="input_box1" type="text" id="text11" name="text11" value="Enter Text1"></p>
</div>

 <div class="text_input1">
<p class="label1"> Text 2 <input class="input_box1" type="text" id="text22" name="text22" value="Enter Text2"></p>
</div>

<div class="text_input1">
<p class="label1"> Text 3 <input class="input_box1" type="text" id="text33" name="text33" value="Enter Text3"></p>
</div>

For adjusting width and height select:

</div>

<h2 class="shape_text_width">WIDTH:</h2>
<div class="iteam_icon2">

<input type="text" id="width" name="width" value="79" onchange="XX()"><p class="mili1">mm</p</input>

</div>
<h2 class="shape_text_width">HEIGHT:</h2>
<div class="iteam_icon2">

    <input type="text" id="height" name="height" value="26" onchange="XX1()"><p class="mili1">mm</p></input>

</div>

To modify the width and height:

$( "#width_label" ).text(79 + " mm");
$("#height_label" ).text( 26 + " mm");

function XX()
{
    var first2 =document.getElementById("width").value;
      var width=first2;
      var width_in_px=width*3.779527559;
      var total_width = Math.round(width_in_px);
      var f_width_in_px = parseInt(total_width);

      var mm_text="mm";

      $('#mySVG1').css("width", f_width_in_px + "px");
      $('#shape1').css("width", f_width_in_px + "px");
      $( "#width_label" ).text( width + " mm");
      $('#width_label').css("width", f_width_in_px + "px");

      var dif=width-300;
      if(width>300)
      {
      $('#height_label').css("margin-right", dif + "px");
      }

} 

 function XX1()
{
    var first22 =document.getElementById("height").value;


      var height=first22;
      var height_in_px=height*3.779527559;
      var total_height = Math.round(height_in_px);
      var f_height_in_px = parseInt(total_height);

      $('#mySVG1').css("height", f_height_in_px + "px");
      $('#shape1').css("height", f_height_in_px + "px");
      $("#height_label" ).text( height + " mm");
      $('#height_label').css("width", f_height_in_px + "px");

}

The dimensions of my output field box and the output text code are outlined below:

<div class="label_fix" id="height_label" style="border-bottom: 1px solid #000;
   width:100px;
   margin: 0 auto;
   margin-bottom: 5px;
   padding: 2px;">
</div>

<svg  style="width:300px;height:100px" id="mySVG1">
     <rect id="shape1" x="0" y="0" style="width:300px;height:100px" stroke="black" stroke-width="1px" fill="white"/>
     <<text id="text1" x="50%" y="25%" alignment-baseline="central" text-anchor="middle" fill="black"></text> 
     <<text id="text2" x="50%" y="50%" alignment-baseline="central" text-anchor="middle" fill="black"></text> 
     <<text id="text3" x="50%" y="75%" alignment-baseline="central" text-anchor="middle" fill="black"></text> 

</svg>

<div class="label_fix" id="width_label" style="border-top: 1px solid #000;
   width: 300px;
   margin: 0 auto;
   margin-top: 5px;
   padding: 2px;">
</div>

To populate values into my output field:

<script>
$( "#text11" )
  .keyup(function(test1) {
    var value = $( this ).val();
    $( "#text1" ).text( value );
    $( "#text_second_1" ).text( value );
    $( "#text_third_1" ).text( value );

  })
</script>
<script>
$( "#text22" )
  .keyup(function(test2) {
    var value = $( this ).val();
    $( "#text2" ).text( value );
    $( "#text_second_2" ).text( value );
    $( "#text_third_2" ).text( value );

  })
</script>
<script>
$( "#text33" )
  .keyup(function(test3) {
    var value = $( this ).val();
    $( "#text3" ).text( value );
    $( "#text_second_3" ).text( value );
    $( "#text_third_3" ).text( value );

  })
</script>

Answer №1

After reviewing your previous comment, I have created a pure CSS solution for what you are looking for. The design requires the image to be in mm, but I have maintained the correct ratio using px. Feel free to adjust the values to achieve the desired results.

To create the illusion of 'holes,' I utilized a background color on the body and applied the same color to the :before and :after pseudo elements within a div.

body {
  background:#ccc;
}
.box {
  box-sizing:border-box;
  background:#fff;
  width:99px;
  border-radius:5px;
  text-align:center;
  padding:7px 0;
  position:relative;
  border:1px solid #000;
  font-size:14px;
}
.box:before,
.box:after{
  content:"";
  position:absolute;
  left:5px;
  display:block;
  width:8px;
  height:8px;
  background:#ccc;
  border-radius:50%;
  top:50%;
  margin-top:-5px;
  border:1px solid #000;
}
.box:after {
  left:auto;
  right:5px;
}

For a live demonstration, check out the following JSFiddle link: https://jsfiddle.net/s6r6frgx/2/

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

What is the best way to evaluate the rows of two specific elements?

My validation process involves comparing individual rows in the clientDocument with the corresponding rows in the serverDocument, instead of comparing the entire documents at once. Currently, I am using the following code snippet for comparison: JSON.stri ...

Transferring PHP session data to another PHP script using an AJAX request

My primary goal is to assist users in recovering their forgotten passwords by using security questions. COMPLETED: I am validating the email entered on the forgot password page with an Ajax post request against the database. If a match is found, I retriev ...

Troublesome glitches in jQuery?

I'm having an issue with the following code: var buggy_brand_name = ['Baby Jogger', 'Babyzen', 'Bugaboo', 'GB', 'Icandy', 'Joie', 'Maclaren', 'Mamas&Papas', 'Ma ...

Creating a tree array in JavaScript from JSON data

I have been struggling to create a tree array from the given JSON data. I have attempted to use filter, map, and reduce methods, but haven't been successful in achieving the desired result. [{ "code": "2", "name": "PENDING" },{ "code": "2.2", ...

What is the process for adjusting the maximum value on my progress bar?

Currently, I am working on a progress bar that is dynamically updating based on predefined variables. Everything seems to be functioning correctly, except for one issue I am facing. When the value of my progress bar reaches the maximum value, there is stil ...

When adjusting the size of the browser window, the div on my web page shifts to the bottom, creating a large empty space at

I have encountered an issue where, when I resize the browser window, my div moves to the bottom and leaves a large space at the top. I would like the div to remain in the center of the page, even if I resize the window to be smaller than the size of the ...

Tips for fixing connection issues when trying to connect to MongoDB on AWS Cloud9

I've been following a tutorial from 'Web Dev Simplified' using the AWS-Cloud9 Ubuntu environment and everything was going smoothly until I encountered an issue while trying to connect to MongoDB. The database appeared to install correctly us ...

Populating dropdowns with JavaScript/jQuery based on the value of the first dropdown

I've been using this particular code to dynamically populate select options based on the first selection. Everything seems to be working perfectly fine until I submit the form with AJAX and then attempt to choose a different option from the select dro ...

Learn how to dynamically display data without the need for refreshing using Vue.js and Laravel

I am looking for a way to display the data that I have successfully inputted into the database without having to reload the page or change components immediately. My current setup involves using vue.js within the Laravel 5.8 framework, along with axios an ...

Difficulty with Bootstrap Carousel (image is displayed but fails to transition/change)

Although I don't have much experience in this, I've searched through various documentations and solutions that have helped others. Unfortunately, I haven't been able to fix my issue, so I decided to create my own post to seek assistance. &l ...

Customize the style attribute in Bootstrap 4 using Popper.js

I've been attempting to adjust the position of a dropdown element, but I'm struggling to make it work. Utilizing Bootstrap 4 with Popper.js, I simply added a default dropdown without any custom styles to my page. However, it automatically applies ...

Expanding the size of one div causes the surrounding divs to shift positions

I am currently working on creating a row of divs that expand when hovered over by the mouse. I have managed to achieve this functionality, but now I want the expanding div to cover its neighboring divs partially, without affecting their sizes or moving the ...

Leveraging JSON Data for Dynamic Web Content Display

I have been attempting to parse and display the JSON data that is returned from a REST API without any success. When tested locally, the API's URL structure is as follows: http://localhost/apiurl/get-data.php It returns data in the following format ...

Retrieve or update the selected option value in a Select2 multiple dropdown

I'm currently using Select2 for multiselect on an input field. My goal is to identify which choice has been clicked, but when I inspect the event triggered upon clicking a choice ("choice-selected"), all I see is event.target.value which contains the ...

Extracting the JQuery library from its source code

Is there a simple method for extracting only the necessary functions from the jQuery library? I have found that many of the functions within the library are not being utilized, so it would be beneficial to remove them. ...

Ensure that the module is exported before the Node.js file completes its execution using the `import`/`export` syntax

In the process of developing an API with express, my objective is to have a separate file for each endpoint. The idea is to create the router in its own file, export it, and then import the endpoint files to be executed. These endpoint files will import th ...

Vue.js encountered an unexpected strict mode reserved word error that was not caught

I have initialized a Vue instance var app = new Vue( {...} ) Additionally, I have defined a class named CustomTooltip class CustomTooltip { constructor(array_data,vue_instance) { this.tooltip_data = array_data; this.vue_instance = vue ...

View two tiled images side by side and seamlessly load them in real-time with our innovative image viewer

Currently, I am working on creating a webpage where two tiled images can be loaded and displayed side by side. The goal is for these images to zoom in together but remain separately tiled. After doing some research, it seems that using Seadragon may not al ...

Issue with implementing setTimeout on await fetch() result

I'm trying to figure out how to add a setTimeout to my request response when using await fetch. Currently, each response is being sent to a DIV in the HTML, but I want to introduce a delay of 5 seconds before each response appears. I attempted this s ...

Challenges with Parsing Dates in JQuery Ajax

Hey there! I've got a table with data in ASP.NET MVC using jQuery Ajax and the initial date output was Date(1665774000000). Unfortunately, when trying to parse it, an error occurred: Invalid Date "<td>" + new Date(parseInt(GetSTTLi ...