Value is not changing in the javascript variable on the onClick event
<p>I am trying to implement a dynamic search jquery and php, but I am not able to change the value of a javascript variable on my onclick event.</p>

<pre><code>&lt;script type="text/javascript"&gt;
  var main_category = '&lt;?php echo $main_category?&gt;';
  var main_url = '&lt;?php echo $url?&gt;get/' + encodeURIComponent(main_category) + '/';
  var container_id = '&lt;?php echo $unique_id?&gt;content_area';

    //name
    $('#&lt;?php echo $unique_id?&gt;search_by_name').autocomplete('&lt;?php echo $url?&gt;get_autocomplete_data/' + encodeURIComponent(main_category) + '/names/', {
      matchContains: "word",
      autoFill: true,
      width: 310
    });$('#&lt;?php echo $unique_id?&gt;search_by_name').result(function (event, data){
      var url = main_url + 'search/title/' + encodeURIComponent(data);
      load_div(container_id, url);
    });


    //on click of displayed categories
    $('[rel="&lt;?php echo $unique_id?&gt;sub_category"]').click(function (){
      window['main_category'] = this.title;
      $('#&lt;?php echo $unique_id?&gt;category').html('' +main_category+ '');
      return false;
    });
  });
&lt;/script&gt;
</code></pre>

<p>It changes the value when  on click is fired</p>

<pre><code>//on click of displayed categories
        $('[rel="&lt;?php echo $unique_id?&gt;sub_category"]').click(function (){
          window['main_category'] = this.title;
          $('#&lt;?php echo $unique_id?&gt;category').html('' +main_category+ '');
          return false;
        });
</code></pre>

<p>but when after that i add data for the search it still searches for the old category</p>

<pre><code>$('#&lt;?php echo $unique_id?&gt;search_by_name').result(function (event, data){
          var url = main_url + 'search/title/' + encodeURIComponent(data);
          load_div(container_id, url);
        });
</code></pre>

<p>"main_category" value is not changing in the "main_url"</p>
