0

I have a dynamic form that I want to append some other html in, but when I want to use the event of my appended html I should include that script in that first script but also I want to add another html in the second script but I don't know how to deal with quotation tags:

      $(document).ready(function(){
    $("#registerNums").on('click',function(){
      var inputnums = parseInt($("#inputnums").val());
      alert(inputnums);
      var outputnums = parseInt($("#outputnums").val());
      alert(outputnums);
      var rulenums = parseInt($("#rulenums").val());
      for(var i=1; i < inputnums + 1; i++){
        var inputmems =
        '<div class="form-row">'+
          '<div class="form-row">'+
            '<div class="form-group col-md-3">'+
              '<label for="inputmems'+ i +'">Enter the number of your input'+ i +' membership functions:</label>'+
              '<input type="text" class="form-control" id="inputmems'+ i +'" name="inputmems'+ i +'" placeholder="Enter inputmems">'+
            '</div>'+
            '<div class="form-group col-md-3">'+
              '<label for="inputname'+ i +'">Enter the name of your input'+ i +' membership functions:</label>'+
              '<input type="text" class="form-control" id="inputname'+ i +'" name="inputname'+ i +'" placeholder="Enter inputname">'+
            '</div>'+
            '<div class="form-group col-md-3">'+
              '<label for="inputrange'+ i +'">Enter the range of your input'+ i +' membership functions:</label>'+
              '<input type="text" class="form-control" id="inputrange'+ i +'" name="inputrange'+ i +'" placeholder="Enter inputrange">'+
            '</div>'+
            '<div class="form-group col-md-3">'+
              '<input type="button" class="btn btn-primary" id="registerMems" value="register mems">'+
              '<script type="text/javascript">'+
                '$(document).ready(function(){'+
                  '$(".registerMems").on("click",function(){'
                    'var inputmems = parseInt($(this).parent().parent().find("#inputmems").val())'+
                      'alert(inputmems);'+
                      'for(i=1;i < inputmems+1;i++){'+
                      '$(this).parent().parent().parent().find(".mem").append('+
                      +'<div class="form-group col-md-4">'+
                        '<label for="memname">Enter the name of your input membership function:</label>'+
                        '<input type="text" class="form-control" id="memname" name="memname'+i+'" placeholder="Enter'+ 'memname">'+
                      '</div>'+
                      '<div class="form-group">'+
                        '<label for="memtype">memtype</label>'+
                        '<select class="form-control" id="memtype" name="memtype'+i+'">'+
                          '<option>trapmf</option>'+
                          '<option>trimf</option>'+
                        '</select>'+
                      '</div>'+
                      '<div class="form-group col-md-4">'+
                        '<label for="memamount">Enter the amount of your input membership function:</label>'+
                        '<input type="text" class="form-control" id="memamount" name="memamount'+i+'" placeholder="Enter memamount">'+
                      '</div>'')'
    }
   });
 });

you can see the complete code at http://jsfiddle.net/Yelesee/h9gm0dje/1/

How do I cope with quotations after the last append?

David C. Rankin
  • 69,681
  • 6
  • 44
  • 72
  • Welcome to stackoverflow please add your code into snippet, So someone has quickly fix your issue. – jaydeep patel Aug 09 '18 at 08:00
  • 3
    Using punctuation in your questions would make them much easier to understand. – fjc Aug 09 '18 at 08:00
  • 1
    this is horrific: `' – mplungjan Aug 09 '18 at 08:04
  • Also you do not actually seem to insert this anywhere. I suggest to use .clone to avoid the concatenation too – mplungjan Aug 09 '18 at 08:10
  • so what can i do with this horrific: http://jsfiddle.net/Yelesee/h9gm0dje/ – Abolfazl Ebadi Aug 09 '18 at 08:30

1 Answers1

1

You can (and should) use template literals to built your string:

var inputmems = `
    <div class="form-row">
      <div class="form-row">
        <div class="form-group col-md-3">
        ...
        ...
`

use the ` symbol in your keyboard for that, which should be somewhere under the escape key

vsync
  • 87,559
  • 45
  • 247
  • 317