I have a dynamically generated form.It has only one text input which value is ID dynamically fetched from database table (table_one). My aim is to submit this ID to another table(table_two). On my page I can see these IDs fetched from the table_one say: 1, 2, 3, 4 ,5, but when I submit any of these IDs say '2', it is only the last ID '5' that will be submitted to table_two. How can I amend my code so that when I submit row 2, ID '2' will be submitted not '5'? Below is my code.
HTML
<form>
<input type="text" id="name" name="name" value="<?php echo $name_id;?>" >
<button type="submit" onclick="return chk()">Edit</button>
</form>
JAVASCRIPT
function chk(){
var name = document.getElementById('name').value;
var dataString = 'name='+ name;
$.ajax({
type:"post",
url:"test.php",
data:dataString,
cache:false,
success: function(html){
$('#msg').html(html);
}
});
return false;
}
PHP
$name = $_POST['name'];
echo "$name";