Advertisement
Guest User

html php jquery

a guest
Feb 14th, 2015
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.70 KB | None | 0 0
  1. <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
  2. <div id="wrapper">
  3.     <div id="title">Change Character Race</div>
  4.     <form action="getchar.php" method="POST">
  5.             <select id="selectacc" name="selectacc">
  6.                 <?php
  7. $conn = new mysqli($host, $dbuser, $dbpass, $authdb);
  8. if ($conn->connect_error) {
  9.     die("Connection failed: " . $conn->connect_error);
  10. }
  11.  
  12. $sql = "SELECT id, username FROM account";
  13.  
  14. $result = $conn->query($sql);
  15.  
  16. if ($result->num_rows > 0) {
  17.     while($row = $result->fetch_assoc()) {
  18.         echo "<option value='" . $row["id"]. "'>" . $row['username'] . "</option>";
  19.     }
  20. } else {
  21.     echo "<option value='' disabled>No characters avalible</option>";
  22. }
  23. $conn->close();
  24. ?>
  25.             </select>
  26.             <select id="race" name="race" disabled></select>
  27.         </form>
  28.         <script>
  29.         $(function() {
  30.             $('#selectacc').on('change', function() {
  31.                 var uid = $(this).val();
  32.                 $.post('functions/testscript.php', {id: uid}, function(data) {
  33.                     //Remove all option-tags in #race
  34.                     $('#race').html('');
  35.                     //Make #race selectable
  36.                     $('#race').removeAttr('disabled');
  37.                     //Loop through all items
  38.                     //and adds them to #race
  39.                     $.each(data, function(i) {
  40.                         $('#race')
  41.                             .append($('<option></option>')
  42.                             .attr('value', data[i].id)
  43.                             .text(data[i].name));
  44.                     });
  45.                 });
  46.             });
  47.         });
  48.         </script>
  49. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement