Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 751333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:39:18+00:00 2026-05-14T14:39:18+00:00

I am trying to implement a dynamic search jquery and php, but I am

  • 0

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”

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T14:39:19+00:00Added an answer on May 14, 2026 at 2:39 pm

    main_url is a variable, and it is only set once. Changing the value of another variable used when setting it does not change its value. You should reset main_url as well. Or better yet, make main_url a function that returns the intended value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to implement a dynamic OPTION list in JavaScript. Depending on other selections
I'm trying to implement a Paypal button with a dynamic value. When I enter,
I'm trying to implement dynamic reloading objects in Python, that reflect code changes live.
I've been trying to implement a dynamic multi-model form with accepts_nested_attributes_for in my rails
I'm trying to implement something like Rails dynamic-finders in Python (for webapp/GAE). The dynamic
I'm trying to implement a function that generates dynamic queries for MNesia. For example,
I'm trying to implement an interface that requires a single property, but I don't
I'm trying to implement a SlidingDrawer that will occupy the full screen width, but
All I am currently trying implement something along the lines of dim l_stuff as
trying to implement a dialog-box style behaviour using a separate div section with all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.