javascript - Removing one option from select dropdown generated by jquery -


i working on basic administrator functionality of social network , came across issue of not being able remove option select dropdown list generated using jquery. dropdown list contains users of social network. administrator upon clicking on "delete account" deletes corresponding record database.

now question being - when click on "delete account" works fine option username still there in dropdown list , possible picked - when picked returns dozens of php warnings , errors because record not in database anymore. how can remove option straight away? tried following, doesn't work.

admin_panel.php (only relevant stuff)

<select name='users' id='users'>         <option value="" disabled selected>select user</option>         <?php             $sql = mysql_query("select * users id <>'".$_session['user_id']."'order username desc") or die(mysql_error());                 $userlist = [];                 while($row=mysql_fetch_assoc($sql)){                     $username = $row['username'];                     $userid = $row['id'];                     $userlist .= '<option name="userid" value='.$userid.'>'.$username.'</option>';                 }             echo $userlist;         ?>     </select></br></br></div>     <div id="user_info">         <!-- generated user info table-->     </div>  <script type="text/javascript">  "$('#user_info').on('click', '#deleteaccount', function(e){     data.command = 'deleteaccount'     data.userid = $('#users').val()     $.post(theurl, data, function(result){         //do want response.         $('#delete_account_success').html(result);     })     $("#users option[value='data.userid']").remove();     $('#delete_account_success').show();     $('#delete_account_success').fadeout(5000); }) </script> 

processuser.php (part of switch statement)

if(isset($_post['command'])){     $cmd = $_post['command'];     $userid = $_post['userid'];   $sql=mysql_query("select * users id='".$userid."'"); $userdata = []; while($row = mysql_fetch_assoc($sql)){     $userdata['userid'] = $row['id'];     $userdata['username'] = $row['username'];     $userdata['name'] = $row['name'];     $userdata['date'] = $row['date'];     $userdata['email'] = $row['email'];     $userdata['avatar'] = $row['avatar'];     $userdata['about'] = $row['about'];     $userdata['admin'] = $row['admin']; }  switch($cmd){  case 'deleteaccount':         $sql= "delete users id =".$userid;         $result=mysql_query($sql);         echo "<img src='pics/ok.png' class='admin_updated_ok'>";     break; } 

on line

$("#users option[value='data.userid']").remove(); 

you're removing option items #users value equal string literal data.userid

try changing to

$("#users option[value='" + data.userid + "']").remove(); 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -