I wonder if somebody could help me please. I’ve got a page that displays results from a database but I want people to be able to edit them. At the moment I’ve got an edit button but that’s doing nothing.
What I’d like is to be able to put the results from the row somebody is trying to change back into the form. Is that possible and how would I go about doing it? One of the problems is that the input names can change as they’re all dynamic and new input fields can be added (as well as old ones removed).
I’ve got the details in the database and am loading them onto the page but the problem I’ve got is allowing people to edit them again if they want. This is the html that I’ve got:
<div id="data" class="data">
<div class="new_form">
<div style="width: 175px;">Date of Birth</div><input class="text" type="text" name="date" id="date" value="">
<div id="form">
<div>
<div style="width: 175px;">First Name </div>
<input class="text" type="text" name="firstname" id="firstname" value=""></div>
<div>
<div style="width: 175px;">Last Name </div>
<input class="text" type="text" name="lastname" id="lastname" value=""></div>
<input class="text" type="hidden" name="gender" id="gender" value="-">
<div>
<div style="width: 175px;">Email </div>
<input class="text" type="text" name="email" id="email" value=""></div>
</div>
<div style="width: 175px;">Website </div>
<input class="text" type="text" name="website" id="website" value=""></div>
</div>
<div style="width: 175px;">Country </div>
<input class="text" type="text" name="country" id="country" value=""></div>
</div>
</div>
<div id="results" style="width:10000px;">
<div class="datacolumn">
<div><span>01 01 2016</span> dob</div>
<div><span>Jane</span></div>
<div><span>Doe</span></div>
<div><span>j.doe@email.com</span></div>
<div><span>jdoe.com</span></div>
<div><span>USA</span></div>
<button id="change" class="button button-accept">change</button>
</div>
<div class="datacolumn">
<div><span>01 01 2016</span> dob</div>
<div><span>Joe</span></div>
<div><span>Bloggs</span></div>
<div><span>j.bloggs@email.com</span></div>
<div><span>jbloggs.com</span></div>
<div><span>UK</span></div>
<button id="change" class="button button-accept">change</button>
</div>
<div class="datacolumn">
<div><span>01 01 2016</span> dob</div>
<div><span>Jane</span></div>
<div><span>Doe</span></div>
<div><span>j.doe@email.com</span></div>
<div><span>jdoe.com</span></div>
<div><span>USA</span></div>
<button id="change" class="button button-accept">change</button>
</div>
<div class="datacolumn">
<div><span>01 01 2016</span> dob</div>
<div><span>Joe</span></div>
<div><span>Bloggs</span></div>
<div><span>j.bloggs@email.com</span></div>
<div><span>jbloggs.com</span></div>
<div><span>UK</span></div>
<button id="change" class="button button-accept">change</button>
</div>
</div>
</div>
and here’s the js:
<script type="text/javascript">
$(document).ready(function () {
$('#change').on("click", function () {
var divs = $(this).parents("div").find("span");
$.each(divs, function (i, v) {
$($(".new_form input")[i]).val($(v).text());
});
});
});
</script>
but it’s not working at all. I don’t get any errors either