On php page in a form, One combo box has list of my Customer from mysql table customer. Another combo box has invoiceno stored in invoice table which has respective customer records. I want to select customer from first combo box and filter invoiceno from the second one according to the customer. Any one help me for php or java or Jquery or both codeings? Means if I select customer1 then in the second combo box should show all invoiceno respective to the custermer1. No Refresh or ReLoad or Post form Pl. If I get the first selection in a php variable format example $customer, it is enough for me. Thanks for any one help me.
Based on what is given, i think one is only restricted to pushing you in the right direction. In a case where you there a large number of customers, it most likely be that you are working with a database, thus the following process:
The Page of the selects is where you will need to make an AJAX request on change of the select element.
Using your JavaScript of your favorite JavaScript library you'll make the request passing a value that you'll query your database for.
Ofcourse you'll need to configure your PHP for GET or POST depending of you AJAX request, then query the database.
Format the databases output to be a valid HTML of your selected element.
Earlier you'll have configured your AJAX script to populate the proper element once the request has been successful.
You dont want to POST to the script. You dont want to invoke any server side activity. And you want to get the value user selects into a PHP variable. From what I understand, this means, you dont clearly get where PHP plays a role. The way you want it, you might want to use XAJAX : http://www.xajax-project.org But even this causes various REQUESTs to the PHP script internally.
I would suggest the below:
Do a natural join in the SQL query.
For a customer C1, there might be 100 Invoice numbers I1. The result of the query may be outputted in a JSON format. Something like this:
"RESULT" : [
"C1" : ["I1", "I2", I3"],
"C2" : ["I11", "I22", I33"]
]
ALL the data will be sent to the browser. This data can be stored as a Javascript Object. Use JSON.parse("<PHP response here>");
Whenever the users selection changes in a combo box, have a function in Javascript to load the corresponding values in the second list.
EDIT: In case, you are dealing with a larger database, and you expect a larger dataset, I would HIGHLY recommend XAJAX -- Simple and easy! :-)
If AJAX is not an option, you must load all the things (include customer & invoice), then you can use pure javascript/css to do that. It's a dirty work around, but it works.
First, let says that you have n customer, so you will have 1 combo box to select the customer; and n combo box for the invoices that associated with them. Those invoice combobox may have id = their ids in database.
Hide all the invoice combobox, with css : display: none
Use javascript: onchange to get the change event in the customer combobox, then show the approriate invoice combobox(display:block). This can be done easily by css property of Jquery, or simply manipulate by javascript replace function (to replace the html class of the combobox)
I'm sure that this way works, but the price is that you must load all data of customers & invoices, which maybe huge. So that if possible, you should try the AJAX approach like Thrustmaster & Babiker propose.
Related
i have a table with columns id, stud_id, stud_name, stud_email, marks. I want a form with 3 drop-down stud_id, stud_name, stud_email. if anyone select any one of the drop-down the others should fill automatically according to the selected field from database. Thanks in Advance.
i want something like this but with a single table
http://www.91weblessons.com/codeigniter-ajax-country-state-city-drop-down/
You didn't post any specifics so my answer can only be general, but so I'll just give you the logical flow of the process:
Javascript that watches the dropdowns for changes. If you have 3 dropdowns, you'll have to watch the first two. If you use jquery, it'll be something like: $('first_dropdown').change({//your ajax call goes here})
Your ajax call. From inside the watch function mentioned above, create an ajax script that calls a php function that gets the data you want to populate the next dropdown. We're not done with this script though, we'll come back to it later.
In your controller, call a function in your model like get_all_stud() and use that to get whatever data you need to populate the dropdown, and echo that data as json.
Now that your controller has returned data to the ajax function we can use it to populate the dropdown. Iterate the object and do something like $('second_dropdown).append({<option>//your data here</option>})
And then you'll repeat the whole thing so that the third dropdown watches for changes on the second dropdown
I have a student management system project, where i am taking student enrollment form online using custom php apps.
When i am inserting enrollment form at the very first beginning of the form there is a drop down list of student iD. my client wants if he / she selects the ID of a particular student from the drop down list, his data will appear in to the text box automatically based on selection.
I know that here i require javascript but i am not sure how to do that.i have searched but didn't found any thing relevant exactly. Can any help me out.
Thanks
You need to first capture the onchange event of the drop down list. When this event fires, you will need to run javascript that makes an AJAX call to the server in order to retrieve the student's data based on the selected student in the drop down list. You will need PHP/MySQL server side code to handle this request. When the AJAX call returns with the data, you will need more javascript to populate the textbox where you want the data displayed.
I won't write the code for you, but hopefully this is enough to point you in the right direction.
Edit: If you need more details, lookup how to create an AJAX call in jQuery. Your requirements are not uncommon, so you should be able to find examples that are very near to what you need. See a relevent tutorial: jQuery AJAX Tutorial
what is the best way to make a pre-canned response feature within a form that submits a query on selection of a drop down list.
(the drop down list is currently populated via php sql foreach loop).
I wish to use the id of the item selected in the drop down, which is stored in the value, to report back to the sql to retrieve the same row of data only a different column....the message also that dynamically populates a text area without having php post from and back to the same page.
If I'm understanding you correctly, why not json encode the data you use to populate the select list, and then take that extra step/lookup out of the process.
Then the onchange for the select list can simply grab the right item from the object and display the message in the text area, as well as set the id in a hidden field if you need that as well.
This way, you've taken the extra call to the server out of the process, and removed at least one additional sql query as well.
I am currently using Jquery UI to display checkboxes, which right now, don't do anything!
you can see the current set up here: rickymason.net/letschat/main/home/
I am still trying to understand JSON, AJAX and Javascript...but i know they are required to make this work:
When the user checks one, or more of the checkboxes, I'd like it to refresh the thread list at the bottom of the page based on which list is checked.
I don't need exact code (though the more the merrier!), just a good outline on the process that needs to take place.
I'm using codeigniter, thus php and mysql. The thread list is generated based on a * query for the threads table. Then, it is filtered based on a session variable which contains all active filters (user input, AND i'd also like it to be selectable via the jquery select box).
Any help is greatly appreciated!
The magic word here is AJAX.
Use jQuery to bind to the events of the form elements
Send the event through AJAX calls to the server
Parse the response from the server and use javascript to update the page
I have piece of code which refresh data periodically (after 5 sec.), and put it into a table.
This table has sorting option, and checkbox to select a particular row.
Now problem is when i want to sort or choose a row using checkbox, because of auto refresh it set whole table data in previous position. Means if any data i had sorted will not show sorted and/or checked row will be unchecked again.
Please provide me some suggestion how to handle this issue.
Thanks
Your alternative might be to do an AJAX call to pull the data periodically instead of refreshing the whole page via PHP. That way you'll be able to send the correct parameters to handle the sort towards the logic within PHP.
OR
You can push named parameters/actions within the url for sorting purposes. Then use URL's on the table header and the page reloads with a url of something like:
http://example.com/table/sort:asc
http://example.com/table?sort=asc
And then your logic could appropriately pick the previously selected areas up.
if (isset($_GET['sort'])) {
//Do sorting stuff
}