It is not working AFTER refresh anymore:
// php
<div style="padding-left:280px;">
<!-- Add -->
<input type="button" class="btnAjouterConfigure" id="add" value="Ajouter" style="text-decoration:none; width:100px; height:41px; line-height:34px; font-weight:bold;" onclick="addnature()"/>
<!-- Delete -->
<input type="button" class="btnSupprimerConfigure" id="delete" value="Supprimer" style="text-decoration:none; width:100px; height:41px; line-height:34px; font-weight:bold;" onSubmit="return deleteRadioButton();">
<div id="fooBar"></div>
</div>
<br />
<div style="height:auto; padding-left:280px;" id="mainRadio">
<?php if(mysql_num_rows($rs)){ ?>
<?php while($row = mysql_fetch_assoc($rs)){ ?>
<div id="<?php echo $row['libelle']?>_r" class="marginTop">
<span><input type="radio" name="<?php echo $row['libelle']?>" id="<?php echo $row['libelle']?>"></span>
<span id="<?php echo $row['libelle']?>_label"><?php echo $row['libelle']?></span>
</div>
<?php }?>
<?php }?>
</div>
<script type="text/javascript">
jQuery(function(){
jQuery('#add').click(function(){
if(jQuery('#xxx_add_e').length){
return false;
}else{
//var name = jQuery.trim(jQuery('#radio').val());
var elem = '<input type="radio" name="" id="xxx_add_e" />';
var row = '<div id="xxx_add_r"><span>'+elem+'</span><span id="xxx_add_label"><input type="text" value="" placeholder="enter value" id="xxx_add_t" /></span> <span id="xxx_add_btns"><span><input type="button" value="okay" id="xxx_add_y" onclick="xaddElement();" /></span> <span><input type="button" value="cancel" id="xxx_add_n" onclick="xcancelElement();" /></span></span></div>';
jQuery('#mainRadio').prepend(row);
}
});
jQuery('#delete').click(function(){
for(var i=0; i<jQuery(':radio').length; i++){
var rad = jQuery(':radio')[i];
if(jQuery(rad).is(':checked')){
//make an ajax call here to delete record from database
jQuery.ajax({
url:'radio.php?delete=1&name='+jQuery(rad).attr('name'),
success: function(){
},
complete: function(){
jQuery('#loading').hide();
}
});
jQuery('#'+jQuery(rad).attr('id')+'_r').remove();
}
}
});
});
function xaddElement(){
var val = jQuery('#xxx_add_t').val();
jQuery('#loading').show();
////Make an ajax call to add element data in database
jQuery.ajax({
url:'radio.php?add=1&name='+val,
success: function(html){
},
complete: function(){
jQuery('#loading').hide();
}
});
jQuery('#xxx_add_btns').remove();
jQuery('#xxx_add_label').text(val);
jQuery('#xxx_add_label').attr('id',val+'_label');
jQuery('#xxx_add_r').attr('class','marginTop');
jQuery('#xxx_add_r').attr('id',val+'_r');
jQuery('#xxx_add_e').attr('name',val);
jQuery('#xxx_add_e').attr('id',val);
}
function xcancelElement(){
jQuery('#xxx_add_r').remove();
}
</script>
// radio.php
<?php
if($_REQUEST['add'] == 1){
$name = trim($_REQUEST['name']);
$sql = "insert into user_nature set ref_user=1, libelle='$name'";
mysql_query($sql);
}
if($_REQUEST['delete'] == 1){
$name = trim($_REQUEST['name']);
$sql = "delete from user_nature where libelle='$name'";
mysql_query($sql);
}
?>