Init function is not working

Need help as init function is not working.

<script>
jQuery(document).ready(function()
 {
MyFunction1.init(); 
  }
);
</script>

<script>
var MyFunction1 = {
init: function() {

  function initialize() {
   jQuery("#MyID").geocomplete(
    {
    details: "MYCSSID",
    detailsAttribute: "data-geo",
    componentRestrictions: {country: 'GB'}
    }
   );
  }
 }
}
</script>

and init:

Is this the correct syntax, an issue with the code or position jQuery(document).ready(function() as code at the bottom works.

<script>
 jQuery(document).ready(function()
  {
   jQuery("#MyID").geocomplete(
    {
    details: "#MYCSSID",
    detailsAttribute: "data-geo",
    componentRestrictions: {country: 'GB'}
    }
   );
  }
 );
</script>

It’s an application logic problem. MyFunction1.init() only defines a function, but doesn’t execute it.

And you don’t even need jQuery.ready if you execute the code just before the closing </body> tag.

I have updated code. How to execute in the correct way. Can you modified my code.

<!DOCTYPE HTML>

<html>

<head>
  <title>Untitled</title>
</head>

<body>
<script>
 var MyFunction1 = {
 init: function() {
   jQuery("#MyID").geocomplete(
    {
    details: "#MYCSSID",
    detailsAttribute: "data-geo",
    componentRestrictions: {country: 'GB'}
    }
   );

  }
 }
</script>
<script>Myfunction1.init();</script>
</body>

</html>
jQuery("#MyID").geocomplete({
    details: "#MYCSSID",
    detailsAttribute: "data-geo",
    componentRestrictions: {
        country: 'GB'
    }
});

although that will do nothing as you do not have the specified Element in your document.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.