View Full Version : Can 1 script perform both a dropdown selection and a radio button choice ?

11-22-2006, 02:29 AM

a. I have a form where a user has to select a company name to update.

b. Currently, i use a code where the first few alphabets of the company name are typed, a radio button used to selected one of the results that pop up and then another 2 scripts update the data.

c. Is it possible to select company name and update on the same form ?

d. My table structures are :

CID(int), Company (varchar) : Table :Customers

CAID(int), CID(int), Cityid(int), Street(var char), Postcode(varchar) : Table : Custaddress

e. So if a user types "exam" , company names like Example inc, Example com get listed. From these, the user chooses say, Example inc. whose address is to be modified.

f. Then another script selects say the 3 addresses linked to Example inc and then again the user chooses one of them to be modified.

g. Then next script allows editing this address and the data thus posted in the final script updates it in the db.

h. I would like steps (e) (f) and (g) to be done on a single form in one script .

i. I cannot use JS as the number of cos. are over 500 .

Would anyone be able to suggest how best I could go about this ? I dont know ajax btw.


11-22-2006, 03:36 AM
First, having 500 companies should be no reason for you to avoid JS. Can you explain that to me? You can query all 500 companies in your database in the blink of an eye.

Second, it would behoove you to learn AJAX. This is what I would use in a situation like this. That way there is no page refreshing and the script updates the form elements (i.e., select menus, radio buttons, etc.) as you go.

For example, when you type in the first few characters of the company's name, a JS onKeyUp event could intercept the characters as they are typed, access a PHP script in the background, compare the characters to the first few characters of all of your 500 companies, the PHP script would return the company names that were matched, and you use some more JS to display the results, placing a radio button next to each result.

An example of the AJAX that does this can be found here: http://www.w3schools.com/ajax/ajax_example.asp

At the end, when you're done building form elements and filling out the form, you submit the form, and then you can update the chosen address in your DB.

My advice: Teach yourself enough JS to fudge things. Then use this tutorial on AJAX: http://www.dynamicdrive.com/dynamicindex17/ajaxroutine.htm

If you absolutely don;t want to learn JS or AJAX, then you will have to refresh the page every time the user inputs something to your form, and you'll need separate pages/forms for steps (e) (f) and (g).

11-22-2006, 10:48 AM
This is what i was afraid of :-(

I have just about taught myself php and to learn js/ajax is to put it mildly , complicated !

Btw, how can i query it in the blink of an eye - my fear of JS stems from the fact that i have to actually write all those names down in the script. For example in the foll script all fruit names have to be mentioned to enable dropdown selection.

<SELECT NAME="Category" onChange="SelectSubCat();" >
<Option value="">Category</option>

function SelectSubCat(){
// ON selection of category this function will work

addOption(document.drop_list.SubCat, "", "SubCat", "");

if(document.drop_list.Category.value == 'Fruits'){
addOption(document.drop_list.SubCat,"Mango", "Mango");
addOption(document.drop_list.SubCat,"Banana", "Banana");
addOption(document.drop_list.SubCat,"Orange", "Orange");

Any suggestions ?

11-22-2006, 12:51 PM
When you query your database, you are effectively running a search on all 500 companies and returning the results.

So if you run a query like:

SELECT * FROM companies WHERE company_name LIKE '%exam%'

You are filling your result set with all possible matches. Once you have your result set, you can dynamically build your HTML select menu with PHP.

You would do all of this in the PHP script called by your AJAX, and then your AJAX callback function would intercept the PHP-constructed select menu from your PHP script, and essentially import it into your current PHP script's form, using something like a JS innerHTML on an empty <div> to display the results.

I guess it's not something that can be easily explained without a solid understanding of the basics of PHP, SQL, and JS/AJAX. I'm afraid that you have your work cut out for you...;)...I don;t see an easy way out on this one...But learning is fun, right? :D

Btw, how can i query it in the blink of an eye - my fear of JS stems from the fact that i have to actually write all those names down in the script. For example in the foll script all fruit names have to be mentioned to enable dropdown selection.

In answer to your question then, the select menu is constructed with PHP instead of javascript, and built dynamically by iterating thru your MySQL result source -- so you don;t actually have to type each company name or address into your code....

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum