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 6832533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:52:13+00:00 2026-05-26T22:52:13+00:00

Why can’t I put the function below inside jQuery(document).ready(function() { } ? function csf_map_maker_js(

  • 0

Why can’t I put the function below inside jQuery(document).ready(function() { } ?

 function csf_map_maker_js( args ) {

      // Default js args.  Args passed to function will override these.
      var default_args = {
        width : 610,
        height : 400,
        latitude :  37.93,
        longitude :  -75.09,
        zoom : 8,
        mtype: 'ROADMAP',
        encoded_points: ' blah blah',
        id: 'csf_map_canvas',
        hood: 'My Neighborhood'
      }; 


      for ( var index in default_args ) {
        if ( typeof args[index] == "undefined" ) {
          args[index] = default_args[index];

        }
      }


     var latlng = new google.maps.LatLng(args['latitude'], args['longitude']);
     var encodedPoints = args['encoded_points'];
     var decodedPoints = google.maps.geometry.encoding.decodePath(encodedPoints);

     var myOptions = {
        zoom: parseInt( args['zoom'] ),
        center: latlng,
        mapTypeId: google.maps.MapTypeId[args['mtype']],
        streetViewControl: true,
        zoomControl: true,
        panControl: true
      };


    csf_map = new google.maps.Map(document.getElementById( args['csf_id'] ), myOptions);

     var encodedPolygon = new google.maps.Polyline ({
        strokeColor: "#0000FF",
        strokeOpacity: 0.55,
        strokeWeight: 5,
        path: decodedPoints,
        fillOpacity: 0,
        clickable: false,
        map: csf_map
     });
}

If I put it outside, the (document).ready block it works, (although I think that some other functions are getting called before the map loads). The code is for a WordPress plugin.

The function gets called in the php script as follows:

$csf_map_output .= '<div id="csf_map_canvas" style="width:'. $atts['width'].'px; height: '. $atts['height'] .'px;"></div>'; 

$csf_map_output .= '<script>var csf_map_params = ' .  json_encode( $atts ) .  '; csf_map_maker_js( csf_map_params );</script>';  

return $csf_map_output;

Do I need to change the way the function is called in the php script when it’s inside jQuery(document).ready(function() { } ?

  • 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-26T22:52:13+00:00Added an answer on May 26, 2026 at 10:52 pm

    if you put your function in jQuery(document).ready(function() { }); and your call of the function from your php is not in jQuery(document).ready(function() { }); your function is called before the function is created, so it does not exist in that moment

    so but both in jQuery(document).ready(function() { }); and make sure your function is declared before its called.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
Can we put functions to determine the condition for our list comprehensions. Here is
Does anyone know how can I replace this 2 symbol below from the string
Can the Application Name passed to SQL Server (via the ADO Connection string) be
Can we do following in SQL Server 2005 query with convert function. MaxRegID =
Can somebody point me to a resource that explains how to go about having
Can anyone (maybe an XSL-fan?) help me find any advantages with handling presentation of
Can you cast a List<int> to List<string> somehow? I know I could loop through
can you recommend some good ASP.NET tutorials or a good book? Should I jump
Can a LINQ enabled app run on a machine that only has the .NET

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.