Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 72388

Trying to make two functions requiring same value but in two input types (div and text)

$
0
0

I am trying to combine two functions into one in an interface. I have looked up div to input pages and yet to find the right answer.

The first function is used to construct a formula which translates it into a string format that is acceptable to another service.

The second function allows me to use an @mention type jQuery which triggers a list to select from as I type when I add a @ symbol in the text.

The problem I have is that the first function only works with a form input "text" and the second function only works if I make the input a div with contenteditable="true".

I have tried to make either function work with the properties of the other and its just no good.

What I think I want is a way of copying the value of the text box into the form input box when I click on Refresh Console button.

Additionally, I only want to show one of them, the one I type in. So that means I want to use the form input field but have it hidden.

Here's my code that has two independently working functions. Where it says "type an at sign here" type an @ and you will see the options. The input box which says "24 + 6 / 10 * 100" is controlling a function where the results are available in the console as 24|6|add|10|divide|100|multiply which is the expected result.

What I want to do is create a formula in the div text box like @net_value + @tax_value which are selectable at each point you add an at sign.

EDIT I have corrected some fundamental issues with the HTML but still have the same issue with a new one, box displays an extra box that I cannot get rid of no matter what I do.

<!DOCTYPE html>
 <html lang="en">
   <head>
     <meta charset="utf-8"/>
     <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
     <script 
     src="https://cdn.jsdelivr.net/npm/jquery@3.4.1/dist/jquery.min.js"> 
     </script>
     <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/ichord/At.js@master/dist/css/jquery.atwho.min.css">
     <script src="https://cdn.jsdelivr.net/gh/ichord/At.js@master/dist/js/jquery.atwho.min.js"></script>
     <link rel="stylesheet" href="dynamic_table.css">
     <title>BODMAS Translation</title><br>

    <h1>BODMAS Translation</h1><br><br>
    <input type = "text" id="f_input" name="formula" value="24 + 6 / 10 * 100">
    <br><br>
    <button onclick="myFunction()">Refresh Console</button><br><br>

    <div id="enter_formula" class="text_input" contenteditable="true">Type an at sign here </div><br>

    <script>
       function myFunction() {
         var operators = {
           '*': 'multiply',
           '/': 'divide',
           '+': 'add',
           '-': 'subtract'
       },
      string = document.getElementById("f_input").value,
      result = string.replace(/\s+([^\s]+)\s+([^\s]+)/g, (_, o, v) => `|${v}|${operators[o]}`);
      console.log(result);
      };
    </script>

    <script>
      $('#enter_formula').atwho({
         at: "@",
         data: ['input.net_value', 'input.tax_value', 'output.description']
        });
   </script>
</html>

Also including the css dynamic_table.css

  table {
    padding-inline: 15px;
    padding-left: 10px;
    border-color: rgb(182, 204, 243);
    border-collapse: collapse;
    border-style: hidden;
    border-bottom: indianred;
    font-family: Arial, Helvetica, sans-serif;
    font-size: medium;
    table-layout: fixed;
    }
 t1 {
    font-family: Arial, Helvetica, sans-serif;
    font-size: larger;
    font-weight: bold;
    }

 thead {
    font-family: Arial, Helvetica, sans-serif;
    font-size: small;
    background-color: rgb(182, 204, 243);
    }

 input {
    width: 600px;
    height: 30px;
    padding: 5px;
    }

 div {
   font-family: Arial, Helvetica, sans-serif;
   font-size: small;
   max-width: 600px;
   height: 40px;
   padding: 5px;
   border: 1px solid rgb(170, 175, 163);
   vertical-align: middle;
   }

tbody {
  font-size: small;
  text-align: center;
  }

.notfirst:hover {background-color: #f5f5f5;}

td {
  height: 30px;
  vertical-align: middle;
  column-span: 2;
  padding-left: 10px;
  padding-right: 10px;
 }

button {
  border-radius: 8px;
  height: 40px;
  width: 100px;
  background-color: rgb(50, 192, 197);
 }

Viewing all articles
Browse latest Browse all 72388

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>