javascript - Pass external var to jquery function -


html file:

<head>    //include jquery </head> <body>     //html stuff      <script type="text/javascript">     var prd = 'something';     </script>      <script type="text/javascript" src="script.js"></script> </body> 

script.js

$('#select span').click(function(){     var id = this.id;      var path = '/scripts/test/sqlgetdata.php?id='+id+'&p='+prd;      path = encodeuricomponent(path);      post(path); });  function post(path){   //stuff } 

the var prd not avaiable on function include in var path.

i've alse tried:

$('#select span').click(function(prd) 

is possible solve without callback? thank you

it's passed event.data

$('#select span').click({prd: prd}, function(e){     var id  = this.id;     var prd = e.data.prd; // here      var path = '/scripts/test/sqlgetdata.php?id='+id+'&p='+prd;      path = encodeuricomponent(path);      post(path); }); 

fiddle


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -