Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Dynamically change post query

  • This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #31166
    avandelay
    Participant

    I’m currently using the following code to display posts from a particular category from a particular month and year.

    It works well, but I would like to make the page dynamic so that the visitor can select a month and year from a drop-down menu and have the content change according the the values selected. See example (1) (2).















    I’m basically looking for a way to translate the action of selecting a month into changing the value of ‘monthnum’ in the queryposts()

    I don’t have much experience with ajax, but I have a feeling that might be useful for this job.

    Can anyone think of a way to do this?

    Thanks!
    -Art

    #67362
    Bob
    Member

    What if you make the value of monthnum a variable, which is taken from a dropdown list or something like that?

    Like this:

    
    
    $monthvar = $_POST["month"];

    query_posts("cat=3&monthnum=$monthvar&year=2011");

    ?>

    I don’t really understand what you want though so I might be wrong here.

    #67336
    avandelay
    Participant

    Thanks Bob,

    Do you know how I could make that work with a drop-down menu?
    I would like to have a drop-down menu that contains a list of the months.
    If the user selected “January” I would want the content on the page to reload, only showing posts from January.

    I understand that in the drop-down menu, the name “January” would correspond to a value of 1; “February” to a value of 2, and so on.

    I don’t know how to write code that would replace the current value of $monthvar in the query_posts(), when January is selected.
    I also don’t know how to write code that would tell the browser to reload new content based on the new values in query_posts() after January is selected.

    If anyone could provide me with some example code I would be greatly appreciative.

    Thanks!

    #67311
    Bob
    Member

    Hmm, what you’re asking for (content being reloaded) will require Ajax indeed, but I don’t know any Ajax unfortunately. So I guess you’ll have to wait ’till someone shows up who does. Good luck anyway.

    #67318
    TT_Mark
    Member

    Yep, what you are looking for is an automatic postback using AJAX which triggers when you make a change to the dropdown menu.

    I’d personally use JQuery for this and, if you take a look at the documentation on their website, it is relatively straightforward.

    Have a go yourself and let us know if you get stuck. There are plenty of people here willing to help

Viewing 5 posts - 1 through 5 (of 5 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.