I am trying to replicate the functionality I have on a dropdown box that allows a user to select a tag and then return articles related to this term,.
The textbox needs to accept a search term and work in the same way. I have tried everything I can think of but I am getting zero results.
To replicate the behavior, select an item from the dropdown box and it will return articles. Then try typing the same term in the search box and it returns no articles.
Any idea why? Here’s the site:
One solution would be to change your search box code to something like this:
Since you are not really submitting a form and don’t want to reload a page, you can just use the
clickevent from abuttonrather than thesubmitevent from theform.If you want to have it get the article when hitting the
Enterbutton, here is one way to do it (there might be better ways I am just not thinking of now…). You can use thekeydownevent to run a function that will test for theEnterbutton. When it finds it, it will callvalidateForm. Add this function to your script:and change your body tag to this:
That attach the
keydownevent listener to thetextboxonce the page has loaded.One note of warning: I am testing this on a Linux laptop running Chrome. I don’t know if Mac calls the
EnterkeyReturnand I don’t know if.keyIdentifieris cross-browser compatible. That is something you need to look into, but this should get you started.