Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7834413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T13:08:46+00:00 2026-06-02T13:08:46+00:00

I’m working on an application using phone-gap. I’m trying to access the contacts on

  • 0

I’m working on an application using phone-gap.
I’m trying to access the contacts on the mobile coz I’ll use them later.
I’m now trying to write a code to find contacts on the mobile.
Here’s the JS file I’m using:

alert('Starting JS');
var TAP = ('ontouchend' in window) ? 'touchend' : 'click';
alert('I entered the function'); 

   document.addEventListener('DOMContentLoaded', function () {
   alert('I entered the second function');

       x$('#friendSubmit').on(TAP, function () {
           var filter = x$('#friendName')[0].value;
           alert('I entered the third function');

           if (!filter)
            {
            alert('Cant find contacts');

                // no contents
                return;
            } 
           else 
           {
              findContactByName(filter, function (contacts) 
              {

   alert(contacts.length + ' contact(s) found matching "' +filter + '"');
  }
); }               

  }); });
  function findContactByName(name, callback) {
       function onError() {
           alert('Error: unable to read contacts');
       };
       var fields = ["displayName", "name"],
           options = new ContactFindOptions();
       options.filter = name;
       options.multiple = true;
       // find contacts
       navigator.service.contacts.find(fields, callback, onError,
       options);
     }

None of the alerts are alerted, so it seems that something is wrong in the code (but it alerted when I removed the “findContactByName” function.

Do you know If I should add any kind of plugins, or update anything so that these functions can work ?
I’m working with cordova version 1.6.1 and I updated the permissions at the manifest to be able to access the contacts.
So, do you know what’s wrong with my code & why isn’t it working?

Thanks a lot.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T13:08:49+00:00Added an answer on June 2, 2026 at 1:08 pm

    Are you waiting for the deviceready event (PhoneGap loaded)?

    The following code works for me to put all contacts with a name field into a names array:

    function onDeviceReady() {
        // specify contact search criteria
        var options = new ContactFindOptions();
        options.filter="";          // empty search string returns all contacts
        options.multiple=true;      // return multiple results
        filter = ["displayName"];   // return contact.displayName field
    
        // find contacts
        navigator.contacts.find(filter, onSuccess, onError, options);
    }
    
    var names = [];
    
    // onSuccess: Get a snapshot of the current contacts
    //
    function onSuccess(contacts) {
        for (var i=0; i<contacts.length; i++) {
            if (contacts[i].displayName) {  // many contacts don't have displayName
                names.push(contacts[i].displayName);
            }
        }
        alert('contacts loaded');
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
I want use html5's new tag to play a wav file (currently only supported

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.