Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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;
share|improve this question

2 Answers

up vote 1 down vote accepted

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

share|improve this answer
Amazeballs! Thanks – howellmartinez 5 hours ago

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.