0

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

Nirav Parmar
  • 148
  • 11

1 Answers1

0

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').

  • after so many days, i found problem in this method too. when i load a.php, then moves to b.php and then again loads a.php.. a.php's functions runs twice. – Nirav Parmar Jan 19 '18 at 10:08
  • That is probably because you are adding multiple listeners to it, when you load the a.php again. Make sure you register(on-page-create) and de-register(on-page-change) listeners appropriately. – Harsh Karanpuria Jan 27 '18 at 04:49