Search code examples
javascriptajaxsmartadmin

Locally defined JavaScript Functions works in All Page


I am using PHPAjax Version of SmartAdmin Template,

in which i am writing some script for specific page,

$(document).on('change', '#vehicle_id', function(){
  var vehicle_id = $('#vehicle_id').val();
  var url = '<?php echo site_url('processor/#../tyres/check_current_km/'); ?>'+vehicle_id;
  window.location.href = url;
});

but it works on every page, suppose i have defined this function on a.php, it also works on b.php


Solution

  • Your listener is implemented on the document, so most likely both the pages are included/ rendered in the same document and hence the script is applied to the complete document.

    If you would like to constraint your script to one page then create page specific unique id and apply listener on that. e.g.('#pageA-vehicle_id').