0846277
0846277

Reputation: 73

How to retrieve user id out of username

I have a input field where you can type in the user id. When typed in, it can display images from that user.

How ever, I would like to type in a username instead of a userid to fetch the images. Does anyone know how I can do that, or which function I could write (how) for that?

Thanks in advance!

Upvotes: 0

Views: 1202

Answers (1)

G.Mendes
G.Mendes

Reputation: 1201

UPDATE: Following this answer, a way to retrieve the ID with a given username https://stackoverflow.com/a/14979901/3032128


If you have a list of users with ids or something you can use autocomplete function from JQuery UI just as this example http://jqueryui.com/autocomplete/#custom-data where you will save the ID from the selected user in a hidden field such as

<input type="hidden" id="user_id">

that is the field that will be processed instead of the one you enter the ID or name,

your javascript will look like

$(document).ready(function() {

 //see JSON datasource for remote load if thats the case
 var users= [
 {
    value: "1",
    label: "JohnDoe"
 } // [...]
 ];
 $( "#user" ).autocomplete({
    minLength: 0,
    source: users,

    select: function( event, ui ) {
        $( "#user" ).val( ui.item.label );
        $( "#user_id" ).val( ui.item.value );
        return false;
    }
 })
});

EDIT: another useful link http://jelled.com/instagram/lookup-user-id

hope that helps

Upvotes: 1

Related Questions