Start function and run function again by clicking the button

Asked

Viewed 326 times

3

When the page fully loads it starts a function, I would like when clicking a button that same function initializes again by passing a text like 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 on the button it doesn’t seem to update by passing the text "pressed" how I would like.

2 answers

1

$(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" />

0

Remove the function initMapplic of the page loading scope:

function initMapplic(title) {
    // ...
}

$(document).ready(function() {
    initMapplic('');

    $("#searchfilters").on('click', function() {
        initMapplic('apertou');
    });
});
  • It didn’t work, it’s still the same thing as the first shipment.

  • Put a alert in $("#searchfilters").on('click', function() { and confirms to me if you’re calling.

  • Yes, you executed Alert

  • Check it out: http://jsbin.com/tesulebowo/edit?html,js,console,output

  • If you also need to use the variable declared in var mapplic, also withdraw your statement from the function scope.

  • The Alert I put here and it also worked, but on the question of function mapplic() run again it seems that it does not run, does not update the div#mapplic

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.