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

  • SEARCH
  • Home
  • 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 7161653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:36:10+00:00 2026-05-28T13:36:10+00:00

Ok, having an issue withe the return value of a function always returning undefined

  • 0

Ok, having an issue withe the return value of a function always returning “undefined”

Heres my code:

//called here:
var res = comms(GENSET_SN);

//the function
function comms(genserial) {
     var Result; 
     //Webservice called here
     MyServices.getCommsState(genserial, "S1", OnComplete1);

     function OnComplete1(args) {
          var Res = eval("(" + args + ")");

          if (Res == 1) {
               Result = 1;
          } else {
                Result = 0;
          }
      }
      return Result;
}

please help!!

  • 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-05-28T13:36:11+00:00Added an answer on May 28, 2026 at 1:36 pm

    I’m guessing MyServices.getCommsState(genserial, "S1", OnComplete1); is an ajax request?

    If so, the value of Result will be returned before it is actually set in the OnComplete1 callback, hence undefined.

    You will need to pass in a callback function containing the code that will use the Result value.

    You can change the code to do this instead, note that you pass in the function to comms and then call it in OnComplete1:

    comms(GENSET_SN, function(res) {
        // do whatever you need with res here!
    });
    
    //the function
    function comms(genserial, callback) {
         //Webservice called here
         MyServices.getCommsState(genserial, "S1", function(args) {
             var Res = eval("(" + args + ")"); // I would change this aswell, dont use eval!
             callback(Res == 1 ? 1 : 0);
         });            
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a small issue with a bit of jQuery: function getQuickResults(terms) { var
Hello everyone I'm currently having 2 issues with the code below: Upon return of
I'm having an issue with the following code: private void DataPortal_Fetch(TaskCriteria criteria) { using
I'm having an issue with updating the database. The app shows the updated value,
Having some issue with my function call please. I have a situation that I
Im having a issue with my code i am working on. I am trying
I'm having an issue with some of my code executing in an unexpected order.
We're having an issue with a poorly coded SQL function(which works fine in live,
I have a javascript function that is called onsubmit: function formCheck(){ return usernameCheck() &&
I'm having an issue when the posting a selection value for server side validation.

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.