javascript – Start function and run function again by clicking button

Question:

When the page fully loads it starts a function, I would like that when clicking a button that same function would initialize again passing a text as Query String . I have the code:

$(document).ready(function() {

    function initMapplic(title){
        var mapplic = $('#mapplic').mapplic({
            source: '<?php echo base_url();?>assets/plugins/mapplic2/server.php?title='+title,    // Using mall.json file as map data
            sidebar: false,          // Enable sidebar
            developer:true,
            minimap: false,          // Enable minimap
            markers: true,         // Disable markers
            fillcolor: true,       // Disable default fill color
            fullscreen: true,       // Enable fullscreen 
            maxscale: 3             // Setting maxscale to 3
        });
    }

    initMapplic('');

    $("#searchfilters").on('click',function(){

        initMapplic('apertou');

    });


});

It starts normally, but when I click the button it doesn't seem to refresh passing the "squeezed" text as I would like.

Answer:

$(document).ready(function() {
    initMapplic("");
});
    
function initMapplic (title) {
  alert(title);
  var mapplic = $('#mapplic').mapplic({
    source: 'assets/plugins/mapplic2/server.php?title='+title,    // Using mall.json file as map data
    sidebar: false,          // Enable sidebar
    developer:true,
    minimap: false,          // Enable minimap
    markers: true,         // Disable markers
    fillcolor: true,       // Disable default fill color
    fullscreen: true,       // Enable fullscreen 
    maxscale: 3             // Setting maxscale to 3
  });
}
Veja se é mais ou menos isso que você precisa.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<input type="button" onclick="initMapplic('apertou');" value="Enviar" />
Scroll to Top