Forum Moderators: coopster

Message Too Old, No Replies

Generating combox from another combo box

Submiting using combo box

         

DNice

10:47 am on Feb 27, 2007 (gmt 0)

10+ Year Member



Hello,

I am using php and mysql and having a problem with
generating a combo box depending on the field selected in another combo box.

Can anybody help please!

Scally_Ally

11:07 am on Feb 27, 2007 (gmt 0)

10+ Year Member



have you got as far as getting the value from the first select box?

it should be something like this

//here you get the first box selection
$selectBox1 = $_POST['selectBox1'];

//now here you can create different select boxes dependant on results
if($selectBox1 == 'option1'){
// write a select box here, or store the code for a particular select box here
}

if($selectBox1 == 'option2'){
// write a select box here, or store the code for a particular select box here
}

hope this helps

Ally

DNice

1:08 pm on Feb 27, 2007 (gmt 0)

10+ Year Member



Hello once again.

Thanks for your solution but i think you did not get me clearly.
I want to create another combo box within the same page depending on selected results before clicking the submit button.

See the HTML for the first combo.

Ministry <select name='ministry' size='1' maxlength='30'>
<option selected value='finance'>Finance </option>
<option value='labour'>Labour </option>
</select>

Thank you.

Scally_Ally

2:40 pm on Feb 27, 2007 (gmt 0)

10+ Year Member



you are gonna have to use some javascript / ajax to achieve this.

option 1. write all your select boxes to the page using php, then use javascript to hide and show relevant select boxes. This will achieve what you want but isnt the most elegant way in the world, but it works.

option 2. have some ajax to communicate with the server when you choose from the first drop down list. This will then repopulate the second drop down list with values stored in a DB or predefined vars.

You cant do what you want with php though because the page will require a refresh

Ally