0

I made this insert table row function. I need to get the values of p_iId, d_prijs, c_prijs, code, artikelNL into the table. How can I do this?

function insertTableRow ( p_iId, d_prijs, c_prijs, code, artikelNL ) { var $id = $('.buttonbewerken[data-id='+p_iId+']'); var row = '<tr>'; row += '<td class="d_prijs ruimte">5427.00</td>'; row += '<td class="c_prijs ruimte">9999.99</td>'; row += '<td class="code ruimte">45t45tdfgr</td>'; row += '<td class="artikelnl ruimte">gdrge5t5</td>'; row += '<td><button data-id= class="buttonbewerken">bewerken</button></td>'; row += '</tr>'; $('#result').prepend(row); } 
0

2 Answers 2

2

You can simply replace them in your string :

 function insertTableRow ( p_iId, d_prijs, c_prijs, code, artikelNL ) { var $id = $('.buttonbewerken[data-id='+p_iId+']'); var row = '<tr>'; row += '<td class="d_prijs ruimte">'+d_prijs+'</td>'; row += '<td class="c_prijs ruimte">'+c_prijs+'</td>'; row += '<td class="code ruimte">'+code+'</td>'; row += '<td class="artikelnl ruimte">'+artikelNL+'</td>'; row += '<td><button data-id="'+p_iId+'" class="buttonbewerken">bewerken</button></td>'; row += '</tr>'; $('#result').prepend(row); } 
Sign up to request clarification or add additional context in comments.

7 Comments

And where can i get the id than? I need to get the id where data id=
What do you mean? Your id is your function first parameter.
I need to get the id on buttonbewerken so i can update it after i inserted it
Oh, I edited my answer.
hmm data id becomes [object Object]
|
1

Simply, if you can use EcmaScript 6

function insertTableRow ( p_iId, d_prijs, c_prijs, code, artikelNL ) { var $id = $('.buttonbewerken[data-id='+p_iId+']'); var row = '<tr>'; row += `<td class="d_prijs ruimte">${p_iId}</td>; <td class="c_prijs ruimte">${d_prijs}</td> <td class="code ruimte">${c_prijstd}> <td class="artikelnl ruimte"${code}></td> <td><button data-id=${p_iId} class="buttonbewerken">bewerken</button></td> </tr>`; $('#result').prepend(row); } 

2 Comments

If you use String templates, at least get rid of all those +=, since it's useless with `
Yeah, much better, i edit

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.