• Hi All,

    I have a problem. I am developing a search/members widget for the sidebar but the problem is that the search widget is supposed to be AJAX/JQuery and when a user starts typing a name then the members on the widget dissapear and then the results come up instead.

    The code works without wordpress however on the widget the Javascript does not seem to work.

    I’ll explain a bit more about the widget to get your heads round it.

    I have one div called Normal and this displays people registered with wordpress sorted by last login. There is a hidden div called LiveSearch. Inside the widget is a text box at the top and when a user starts typing a name the Normal div should dissapear and the LiveSearch should appear. Inside the code I have a javascript file called scripts.js and a search.php file. the js file loads dynamically the search.php file and using the innerhTML tag it populates the search results after each keyup but the js isn’t working so even when I type something in it returns nothing but the Normal div.

    I have tried echoing the javascript when the widget is displayed and also tried enque script function and none works.. does anyone have some example code I can check my code with or offer suggestions?

    Regards

    Ashley Johnson

Viewing 1 replies (of 1 total)
  • Is your script dependent on any JS libraries? jQuery, jQuery UI etc? If so these will need to be loaded on the page before your scripts executes.

    There should be no problem in principle with adding your JS locally in your widget. Just embed the script tag in your widget code:

    <script type="text/javascript" src="myscript.js"></script>

    Just make sure your path to your JS files is correct.

Viewing 1 replies (of 1 total)
  • The topic ‘Javascript within Widget’ is closed to new replies.