ismail alaoui
ismail alaoui

Reputation: 6073

How to insert a textfield value in td

i need to insert value from textfield in a table , with jQuery . I have a table with three cells , and i use a jQuery function to append element on my table , but i can't get the value of my textfield in the td .

this is my table:

<table id="tableCmp" border name="tableCmp" style="width:25%;border-collapse:collapse;">

<tr>
<th width="5%"></th>
<th>Intitule Compagnie</th>     
<th width="15%">Action</th>
</tr>
</table>

this is my text field:

<input type="text" id="text" />

this is my function:

function showdata()
 {
 $('#tableCmp').append('<tr><td  style="text-align:center;"><input type="checkbox" name="myTextEditBox" id="myTextEditBox"></td><td>$('#text').val()</td><td><input type="button" value="M" /><input type="button" value="X" /></td></tr>');
 }

Upvotes: 1

Views: 1052

Answers (2)

Abhishekh Gupta
Abhishekh Gupta

Reputation: 6236

You can try this:

function showdata()
 {
   $('#tableCmp').append('<tr><td  style="text-align:center;"><input type="checkbox" name="myTextEditBox" id="myTextEditBox"></td><td>' + $("#text").val() +'</td><td><input type="button" value="M" /><input type="button" value="X" /></td></tr>');
 }

Upvotes: 2

Namit Singal
Namit Singal

Reputation: 1516

You have added $("#text").val() inside of the brackets, Try using this

$('#tableCmp').append('<tr><td  style="text-align:center;"><input type="checkbox" name="myTextEditBox" id="myTextEditBox"></td><td>' + $('#text').val() + '</td><td><input type="button" value="M" /><input type="button" value="X" /></td></tr>');

Upvotes: 1

Related Questions