0

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!

0846277
  • 73
  • 3
  • 11

1 Answers1

1

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

Community
  • 1
  • 1
G.Mendes
  • 1,201
  • 1
  • 13
  • 18
  • Hello, I don't have a list of user id's. The meaning is that when you use my web application, you can check out pictures of a user with the name 'Mendes' for example. – 0846277 Nov 26 '13 at 15:21
  • Hey, doing a quick search on stackoverflow I found this answer that pretty much is what you need to get user_id from username, guess that will do the part of looking up the ID so you can retrieve the pictures. Edited my answer http://stackoverflow.com/a/14979901/3032128 – G.Mendes Nov 27 '13 at 10:44