Search code examples
javascriptsplitconcatenation

String split since blank space


I have a problem with the next code

     html:'<div class="row">'+
            '<div class="form-group col-sm-12">'+
                '<label for="pedidonom">Name</label>'+
                  '<input type="text" value='+e.getAttribute("name")+' class="swal2-input" id="nombre" placeholder="Parisina">'+
            '</div>'+
            '<div class="form-group col-sm-12">'+
                '<label for="pedidonom">Description</label>'+
                '<input type="text" class="swal2-input" id="description" placeholder="Parisina" value='+description+'> '+
                '<input type="hidden" value='+e.getAttribute("idlookup")+' class="swal2-input"  placeholder="Parisina">'+
            '</div>'+
        '</div>',

The problem is that in value='+description+' only shows first word.

I print the var description in the console and shows the complete text I think I'm doing incorrect concatenation help please


Solution

  • You are missing the " " in every value, it could be value=" '+e.getAttribute(\"name\")+' " and you must escape the quote marks, perhaps it will help you if you use temple quotes, so you would end with something like this:

    html:`<div class="row">
            <div class="form-group col-sm-12">
              <label for="pedidonom">Name</label>
              <input type="text" value="${e.getAttribute('name')}" class="swal2-input" id="nombre" placeholder="Parisina">
            </div>
            <div class="form-group col-sm-12">
              <label for="pedidonom">Description</label>
              <input type="text" class="swal2-input" id="description" placeholder="Parisina" value="${description}">
              <input type="hidden" value="${e.getAttribute('idlookup')}" class="swal2-input"  placeholder="Parisina">
            </div>
          </div>`
    

    Temple quotes let you write blocks of code or format texts without the need to close and open string quotes, and you can interpolate variables in the text using ${variableName}.

    Hope it helps.