howellmartinez
howellmartinez

Reputation: 1275

Passing HTML dynamic table row data to PHP / Laravel

I am using an HTML table and dynamically adding rows to it via Javascript. I am trying to pass the data from these rows to PHP / Laravel using input="hidden". Adding the rows to the HTML page seems to work fine, however I can't access the data when I call them from my PHP script. ($test doesn't seem to return anything) Any ideas why? Thanks!

HTML:

<table id='mytable'>
</table>
<input type='button' id='btnAddRow' value='Add' onclick='javaScript:addRow();'>

JS:

function addRow(){
    var newRow = document.all("mytable").insertRow(-1);
    var cell = newRow.insertCell(-1);
    cell.innerHTML = "<input type='hidden' id='mydata' value='hello'>";
}

PHP:

$test = Input::get('mydata');
return $test;

Upvotes: 0

Views: 2133

Answers (2)

Anujan
Anujan

Reputation: 938

It should be name="mydata" rather than id='mydata'

Upvotes: 1

php_nub_qq
php_nub_qq

Reputation: 16015

In order to pass data from the rows to PHP dynamically you need to make xmlhttprequests (ajax)

Upvotes: 0

Related Questions