1

I am a student studying JavaScript. I want to put the checkValue value in the strong tag into the input box, but I don't know how to write JavaScript to get it into the input box. Do I need to find cart_table of div? Or should I find a strong tag?

<script>
$().ready(function() {
   $("#optionSelect").change(function() {
       var checkValue = $("#optionSelect").val();
       var checkText = $("#optionSelect option:selected").text();
       var product = $("#productname").text();
       var price = parseInt($("#price").text());
       var test = parseInt($(this).find(':selected').data('price'));
       var hapgae = price + test

       if (checkValue != "no") {
           var whtml =
               "            <div class=\"cart_table\">\n" +
               "            <hr style='width: 300px; margin-bottom: 30px;'>" +
               "            <p style='font-size: 17px;'>" + product + "</p>" +
               "                <p style='font-size: 13px; margin-top: -10px; class=\"check\" margin-bottom: 20px;'>" + checkText + "</p>" +
               "                        <strong class=\"value_code2\">" + checkValue + "</strong>\n" +
               "                   <input name=\"value_code\" id=\"value_code\" class=\"value_code\">" +

Strong tags and input tags refer to this part.

               "                        <strong class=\"value_code2\">" + checkValue + "</strong>\n" +
               "                   <input name=\"value_code\" id=\"value_code\" class=\"value_code\">" +
Toto
  • 89,455
  • 62
  • 89
  • 125
Rhdehd
  • 57
  • 1
  • 1
  • 9

1 Answers1

1

first of all i would recommend you to use backticks

var html = `
  <div>
    <span>Some HTML here ${some_var}</span>
  </div>
`; 

this saves you time and effort, and you can then insert variable wherever you want

also check this thread

Creating multiline strings in JavaScript