I'm hoping to create a fairly simple 'filter by multiple checkbox' search tool for a website... and I don't know where to begin with live updating results within a specified div as soon as someone selects/deselects a checkbox.
I hoping to build a filter system similar to this page:
http://thegatewayonline.com/articles/
... I want to have a system where clicking on each checkbox triggers a form submit, which loads results into a specified DIV on the same page.
Do you have any pointers towards, or code snippings, which could help me get started?
I am coding using PHP.
Thank you so much in advance for your help!
Joe
You'll want to issue an $.ajax call via jQuery when a checkbox is hit:
$('.checkbox').click(function() {
// ajax call here
});
Within the AJAX call, there is a callback function called success which contains a data parameter. You can echo a JSON object from a PHP page (which loads the available articles from your database) and have it passed as this parameter. Then, you simply decode this JSON object and print your content on the page.
JSON Reference: https://developer.mozilla.org/en/JSON
jQuery Ajax: http://api.jquery.com/jQuery.ajax/
Related
I am designing a web page. I want to have the options(of another drop-down list on same page) based on the selection made by the user.
I am providing a drop-down list to the user called Application. Depending on the Application, I want to query sql and want to show only the options that are valid for selected Application in another drop-down list.
I want to get the value of Application on the same page (one that user has selected) and by getting that value will query the sql accordingly.
Once the page is loaded, the PHP cannot do anything more.
You cannot use PHP based on user interaction.
The only way to do so is through javascript.
Using ajax, you can retrieve data from a certain URL on your javascript.
A procedure would be like this:
User selects something
The javascript(ajax) loads a URL
In that URL, use your PHP to fetch a certain query
The result would be sent to javascript, so display the result.
Here's a good page explaining ajax:
http://wabism.com/ajax-tutorial-with-jquery/
you have to call an ajax function on the onchange event of dropdown that gets data from database.
ajax is your friend. Either you can use raw javascript or jquery( easier ). Your steps would be..
1. Write a php code block, most probably a function, which takes the selected application option from post, queries the database and outputs the result.
2. In your current page, write a js code that fires the ajax request each time user selects an option. This ajax will send the selected option to the php script by post method and u can grab the output upon the success of the request.
$('.selectBox').on('change', function(){
// do your ajax here.
});
something like that..
I need to take form data from user input- i.e. radio buttons and use that to apply search filters to a database search.
However there are specific parameters which are giving me difficulty.
Specifically: The search filter options pane is a static fixture on the main page of the site. The query to be modified by the search filters is a separate php page which is called by an ajax function to display search results in the middle of the page without page refresh.
Is it even possible to submit variable values to another php page without going to that page and processing the php immediately? Or will the variables not be stored like that?
The code is too long but I'll give basic pseudocode:
Form action="Query Page to receive user input.php"
Some radio buttons:
20
15
10
Submit button--> Submits the radio button value to QueryPage.php but does not redirect
User clicks a category link (i.e. fitness) that calls the ajax function which displays the output of QueryPage.php. At this point QueryPage.php should perform the search with the specific user input filters that were selected earlier.
Is this possible?
Let me see if I understand correctly:
You're basically saying that your radio buttons will modify the search results, based on the what user selected?
If that's the case, I can think of 2 options:
1- When you make the ajax request for the search, first, grab the user input and send it to the QueryPage.php file with the search query. Do you have access to that function?
2- Post the user input using ajax (are you using jQuery or some other library for this?) to a UserInput.php file, where you'll store that data on the session, and then from QueryPage.php you just access the session and grab the values sent previously.
Does that answer your question? Sorry if it doens't, it's a bit hard to understand the problem.
You can use JQUERY and its events method. For example change,click,hover. In your case you want to use radio buttons, so you might wanna use the click event for that.
$("#radio").click(function () {
// SEND HTTP REQUEST
});
http://www.mkyong.com/jquery/how-to-select-a-radio-button-with-jquery/
Yes. You could just use .ajax(), or .post() or cURL. This will post your data to the specified page without redirecting.
Example using .post()
$.post("test.php", { name: "John", time: "2pm", fieldname: "your value" } );
I am building a page with a button which opens a popup and allows to create a new record in MySQL table. Now I would like to refresh part of the parent page with summary results after the popup window closed. Could you please let me know if there are any examples or sample code? I gooled but couldn't find any example. Thanks for your help.
Are you using any JS lib?
Assuming you are using jQuery + jQuery UI for popup, you can look at jQuery UI modal form example (one note - there is no ajax used, but it's fairly simple to do so).
Idea is simple, bind to onClose popup event, serialize form, submit, and insert recived data into page content.
I guess you will need to call javascript function of parent which will change a particular div based upon your requirement..
I'm trying to implement a search for my project , but i can't figure it out how to use ajax and get data to the view, can some one help me with this?
(this is my first project using codeignter and jquery)
regards,
Rangana
Here's a quick overview:
You need to create an input box (obviously).
On your js file, you give that input an event (keypress or anything you want) and when the event triggered you send an ajax post request to your controller method.
On your controller method you read the post request, then do a DB search, you return the result to your js by 'echoing' the DB search result using your preferred format (JSON, xml, etc).
You process the result on your js file using callback.
codeigniter and jquery are unbeatable
see if this can help ...
I would like to create a pagination system for comments in my website.So far, I have been able to create pagination using php/mysql and html but the page has to refresh every time we click on the next button(for the next set of comments) or previous or a particular page....
As far as my knowledge of jquery is concerned I am thinking that, when the user clicks on the next button we post data for the page number to comments.php then echo all the comments in comments.php, then the jquery data variable recieves all the data echo'd in the file and appends it to the #comments box...
Is my solution a valid one??? or anyone has a better solution.....thanks
Your question doesn't make much sense and is very jumbled.
You can either load the entire list when the page first loads, and use jquery to paginate it by hiding the extra entries, which will work fine for lists with a few pages worth of content.
The other option is to use AJAX to fetch the next or previous page when the appropriate link is clicked.
There are plenty of pagination add ons for jquery. Maybe check them out.
Don't use a POST request to get the next page as it looks like you might be, unless you are just using the wrong terminology.
Yes, when you click 'next', you send ajax request to comments.php and replace current comments with new ones.
You can do it with a get()/getJSON() call in jQuery.
Something like
$('#next').click(function(){
$.getJSON('url?withnextpage=number',
function(data){
//update variables or the DOM
});
});
Returning it in JSON may be quicker. I hope that helps