Load data into textbox on selection of dropdown list - php

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

Related

Gravity Forms + jQuery + PHP + ajax

Well. This is complicated, so I'll explain it the best I can.
What Works: If you visit https://goatthroat.com, you will see a Gravity Forms form on the homepage with the heading "Find the Right Pump." Here is how this form works:
1. I have uploaded a CSV that is a table of ALL of these chemicals and their pump compatibility (see https://www.goatthroat.com/support/complete-chemical-liquid-compatibility-guide/ -- which is a table also generated by this CSV)
The dropdown menu on this FIND THE RIGHT PUMP form is automatically populated from that CSV
The user enters the info as prompted, and it generates a query string to return the appropriate results (i.e. https://www.goatthroat.com/pump-recommendation/?chem=3M+Adhesion+Promoter+4298UV)
Goal: On another form on another page (https://goatthroat.com/quote-request), there is ANOTHER dropdown with the same list of chemicals.
I would like to be able to incorporate their search results IN THE FORM. In other words (and I know this may seem unclear): fetch, using ajax I assume, the results of this form search LIVE and include them in the form submission.
This is a bit more technical than I usually get, so any help is much appreciated.

Search field within a form and then do something with all the chosen results

I would like to offer the ability for users to open a form built using PHP/HTML and then on that form have a box which allows them to search for employees then want to send the form to without having to submit the form at this stage.
They will get a search box which allows them to enter the name or part name, the query then finds all employees which match the input string and they then choose the correct employee and that respondent is added to a list and they then search for the next employee and so on until they have added as few or many as they like.
Once they have selected the names, they then fill in some other standard fields on the form and then a separate entry is created in the "forms" table for each request sent.
Happy how to do the last part in terms of entering it into the database etc and how to do a "normal" search in PHP/MySQL but what should I do for the search within a form and add to the list pre submitting?
the technique you are looking for is AJAX which uses javascript to examine the form field as they type, talk to the php, get data, then show it back to the user without having to reload the page or sumbit the form. The exact thing you describe is called auto complete which there are many prebuilt tools for (or you can build your own custom one with some js knowledge). I am not going to try to post all the code here since it would be rather long and involved but if you search around these terms you will surely find what you need.
This can all be achieved with Javascript.
If you have a small number of employees, you could send an array of employees with the page. Use an 'onchange' event in the form field so that with each keypress you run a lookup matching the employees against the typed text.
It's likely that you don't have a small enough number of employees, and also I'm not sure best practice advocates sending your entire company address book inside a web page! In that case you will need to do the same using Javascript ajax calls within the page. On each keypress, fire a request back to the server asking for employees matching the text string.
You will need to dynamically display the matching employees in another form widget that allows for selection, or maybe as text with checkboxes etc.
There are plugins that manage all the client side part of this but you will still have to put together your own web service to do the employee lookup.

PHP on a site with dynamic content

SO FAR I have made a website which is connected to a MYSQL database. On the website I have many buttons, each button corresponds to a table in my database. When I click the button, a javascript function opens my php file in this form
xmlhttp.open("GET", "addPoint.php?q=" + name, true); Where name is the name of the table
Back to the html. I have a div with an ID that will update with whatever the PHP echos.
The div is now populated with table, reflecting the table in mysql. This all works fine.
Here is the problem: I am trying to implement a voting system, where you vote by clicking on one of the elements of the newly created table. AFAIK the MYSQL updating which will need to happen for the vote to work, will need to be done in PHP, which means that I need to tell the PHP file
The name of the table
The name of the element
I am reluctant to use forms because I would like to just be able to click some text, NOT have to fill in a form or click a radio button.
So how do I get these 2 bits of info to a PHP file? Is the structure which I am doing this any good or should I step back and redesign?
Thanks for reading please let me know if I have been ambiguous.
Familiarize yourself with JQuery. It's great for projects like these.
http://www.w3schools.com/jquery/default.asp
As Norse already alluded to, use javascript to submit a "form" request for you. The javascript can populate the table and element values for you based on the button which was clicked. It is up to you whether this is a GET/POST.
JQuery would be a great way to help make this easier, but you don't need it if you don't want it.

On select/unselect of checkbox, query DB, return array, then update array without refresh

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

Php Two Combo box in a form control each other. How?

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.

Categories