Value is not changing in the javascript variable on the onClick event

Posted by Chetan sharma on Stack Overflow See other posts from Stack Overflow or by Chetan sharma
Published on 2010-04-26T09:44:39Z Indexed on 2010/04/26 9:53 UTC
Read the original article Hit count: 356

Filed under:
|
|

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.

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

    //name
    $('#<?php echo $unique_id?>search_by_name').autocomplete('<?php echo $url?>get_autocomplete_data/' + encodeURIComponent(main_category) + '/names/', {
      matchContains: "word",
      autoFill: true,
      width: 310
    });$('#<?php echo $unique_id?>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="<?php echo $unique_id?>sub_category"]').click(function (){
      window['main_category'] = this.title;
      $('#<?php echo $unique_id?>category').html('' +main_category+ '');
      return false;
    });
  });
</script>

It changes the value when on click is fired

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

but when after that i add data for the search it still searches for the old category

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

"main_category" value is not changing in the "main_url"

© Stack Overflow or respective owner

Related posts about php

Related posts about JavaScript