Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
- <div id="wrapper">
- <div id="title">Change Character Race</div>
- <form action="getchar.php" method="POST">
- <select id="selectacc" name="selectacc">
- <?php
- $conn = new mysqli($host, $dbuser, $dbpass, $authdb);
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- $sql = "SELECT id, username FROM account";
- $result = $conn->query($sql);
- if ($result->num_rows > 0) {
- while($row = $result->fetch_assoc()) {
- echo "<option value='" . $row["id"]. "'>" . $row['username'] . "</option>";
- }
- } else {
- echo "<option value='' disabled>No characters avalible</option>";
- }
- $conn->close();
- ?>
- </select>
- <select id="race" name="race" disabled></select>
- </form>
- <script>
- $(function() {
- $('#selectacc').on('change', function() {
- var uid = $(this).val();
- $.post('functions/testscript.php', {id: uid}, function(data) {
- //Remove all option-tags in #race
- $('#race').html('');
- //Make #race selectable
- $('#race').removeAttr('disabled');
- //Loop through all items
- //and adds them to #race
- $.each(data, function(i) {
- $('#race')
- .append($('<option></option>')
- .attr('value', data[i].id)
- .text(data[i].name));
- });
- });
- });
- });
- </script>
- </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement