1

I am querying a mysql database and returning some user info including their access level. As the user level either 1 or 2 comes back from the database how do I have their user level selected using jQuery.

<select id="dropdown">
<option  value="1">Admin</option>
<option  value="2">General</option>
</select>

I want to set accesslevel to be what ever access level the user has:

$(document).ready(function(){
    $("#dropdown").val('accesslevel');
});

Sorry but I am an absolute beginner. I tried to get access level from php variable name using this but its not working.

<?php $accesslevel; ?>

1 Answers1

0

You don't even need to use jQuery for that, it can be handled with just PHP like this:

<?php

    echo '<select id="dropdown">';

    if ($accesslevel == 'admin') {

        echo '<option value="1" selected>Admin</option>';
        echo '<option value="2">General</option>';

    } else {

        echo '<option value="1">Admin</option>';
        echo '<option value="2" selected>General</option>';

    }

    echo '</select>';

?>
Tamaki
  • 53
  • 7
  • This would work although increases code length. Jquery answer would be nice as I thought I was close to what I need to get it to work. – Barney Gorilla May 24 '15 at 16:10