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\">" +

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

5 Comments

Thank you, but I just want to put the checkvalue in the input box.
what do you exactly mean? you want to render(show) input depending on if condition on checkvalue, or you to put checkvalue variable in input
var checkText = $("#optionSelect option:selected").text(); I want to put this value in input name="value_code".
` <input name=${checkText}> `
Thank you for the information. I'm glad that you asked me about the purpose of the problem and tried to solve it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.