0

I have a list that has several option. I dynamically set an event that whenever a button is clicked, create a table and text input and put the value of list in in there, but I have option that have number value but it didn't set to the value of that input. See my code.

My jquery code:

$("#table_drugs").append("<tr><td>"
    + $("#drugs_list").val() + "<input type='text' name='past_druges_used' value="+$("#drugs_list").val()+">"
    + "</td><td>" + $("#drugs-explain").val()+"<input type='text' name='how_to_use' value="+$("#drugs-explain").val()+">"
    + "</td><td>" + "<button type='button' class='col-sm-7 btn btn-danger pull-right'>delete</button> "
    + "</td></tr>");

And my html:

    <div class="col-md-12">
        <div id="drugs_list_div" class="form-group">
            <div class="col-md-4 col-md-offset-6">
                <select id="drugs_list" class="form-control" style="font-family: font-style-3;">
                    <option>empty</option>
                    <option>Drugs 1</option>
                    <option>Drugs 3</option>
                    <option>Drugs 2</option>

                </select>
            </div>
        </div>
        <div id="drugs-explain-div" class="form-group">
            <div class="col-md-4 col-md-offset-6">
                <input type="text" class="form-control" id="drugs-explain" style="font-family: font-style-1;">
            </div>
        </div>
    </div>
        <div class="col-md-12">
            <div id="table-drugs-div" class="col-xs-11 list-hide">
                <table class="table table-striped" id="table_drugs">
                </table>
            </div>
        </div>
4
  • I can't get U what do you mean by mkay!!! Commented Jul 25, 2014 at 12:32
  • Sorry man.. I do not understand your question, sorry i can't help.. So i decided to try and make people laugh Commented Jul 25, 2014 at 12:36
  • @3rror404 I suspect you haven't understood what it's supposed to do, then. It definitely doesn't work if you select an option with a space in its text from the dropdown. Commented Jul 25, 2014 at 12:38
  • 1
    @MarkRijsmus Don't worry I got my answer and sorry for using drugs :) Commented Jul 25, 2014 at 12:40

1 Answer 1

3

You need to put quotes around your values:

$("#table_drugs").append("<tr><td>"
    + $("#drugs_list").val() + "<input type='text' name='past_druges_used' value='"+$("#drugs_list").val()+"'>"
    + "</td><td>" + $("#drugs-explain").val()+"<input type='text' name='how_to_use' value='"+$("#drugs-explain").val()+"'>"
    + "</td><td>" + "<button type='button' class='col-sm-7 btn btn-danger pull-right'>delete</button> "
    + "</td></tr>");
Sign up to request clarification or add additional context in comments.

Comments

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.