<a href="#" data-id="<?php echo $hist_id; ?>" class="showme btn btn-orange btn-single btn-xs">Aanpassen</a>
<script type="text/javascript">
jQuery(function($){
$('a.showme').click(function(ev){
ev.preventDefault();
var uid = $(this).data('id');
$.get('aanpas-modal.php?id=' + uid, function(html){
$('#modal-7 .modal-body').html(html);
$('#modal-7').modal('show');
});
});
});
</script>
De bedoeling is dat er dan een popup opent met een aanpaspagina, daarvoor moet ik dus de data-id attribute meesturen en dat doe ik in de javascript. Dit alles werkt prima.
Nu wil ik daaronder nog een link zetten om hetzelfde te doen:
<a href="#" data-id="<?php echo $hist_id2; ?>" class="showme2 btn btn-orange btn-single btn-xs">Aanpassen</a>
<script type="text/javascript">
jQuery(function($){
$('a.showme2').click(function(ev){
ev.preventDefault();
var uid = $(this).data('id');
$.get('aanpas-modal.php?id=' + uid, function(html){
$('#modal-7 .modal-body').html(html);
$('#modal-7').modal('show');
});
});
});
</script>
Die popup opent ook maar hij past mijn pagina niet aan. Bij de eerste wel. Voor beide gebruik ik aanpas-modal.php:
<?php
$id = $_GET['id'];
echo 'ID: '.$id;
require ('config.php');
$conn = mysql_connect($host,$user,$pass) or die (mysql_error());
mysql_select_db($dbnm) or die (mysql_error());
$sql = "SELECT * FROM historiek WHERE id = '". $id ."'";
$res = mysql_query($sql) or die (mysql_error());
while($row = mysql_fetch_assoc($res))
{
?>
<div class="row">
<form role="form" method="post" id="historiek">
<div class="form-group">
<textarea class="form-control ckeditor" id="editor10" name="historiek" rows="10"><?php echo $row['historiek']; ?></textarea>
</div>
<div class="form-group">
<button id="Submit1234" type="submit" name="Submit" class="btn btn-info">Wijzigen</button>
</div>
<input type="hidden" name="id" value="<?php echo $id; ?>">
</form>
</div>
<script>
$(function(){
$('#Submit1234').click(function(e){
e.preventDefault();
//alert($('#editor10').val());
$.post('aanpas-modal-process.php',
$('#historiek').serialize(),
function(data, status, xhr){
//alert('Gelukt!');
//$("#thanks").html(data) //hide button and show thank you
alert('Opgeslagen... Sluit popup!');
});
});
});
</script>
<script type="text/javascript">
jQuery(function($){
$('#editor10').ckeditor();
});
</script>
<?php } ?>
Op die pagina krijg ik wel iedere keer de juiste id waarde mee.
Hoe zou dit komen? Iemand een idee?
Voor alle duidelijkheid nog even de aanpas-modal-process.php:
<?php
//grab named inputs from html then post to #thanks
if (isset($_POST['historiek'])) {
$id = strip_tags($_POST['id']);
$historiek = strip_tags($_POST['historiek']);
require ('config.php');
$conn = mysql_connect($host,$user,$pass) or die (mysql_error());
mysql_select_db($dbnm) or die (mysql_error());
$sql = "UPDATE historiek SET historiek = '$historiek' WHERE id = '". $id ."'";
$res = mysql_query($sql) or die (mysql_error());
}
?>
Dit topic is ook gepost op http://www.pfz.nl/forum/topic/11071-javascript-probleem/