Php coding of 2 level drop down

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
fabienzan
Forum Newbie
Posts: 1
Joined: Sun May 18, 2014 3:52 pm

Php coding of 2 level drop down

Post by fabienzan »

Hi,

I have the following registration form on our website (this is only part of the code).
The last line of this code is about States in Australia. We are now adding some new countries like New Zealand and I need to ad new states for new Zealand but I want them to show separately in the drop down box like on the following
website location field : http://www.seek.com.au/
So the country would be in Bold and then you would have a second level of information per country with the states.
Could you please let me know how to modify my code to do that ? (my php coding is extremely basic so please feel free to treat me as a dummy coder)

Thanks

<table width="70%" border="0" style="margin:0 auto;">
<tr>
<td colspan="3" style="text-align:center">
<h4 style="text-align:left">Register now and join the fun!</h4>
<p style="text-align:left">Please fill out the form below to register. We can only accept registrations with your valid email address. We will contact you when you have been selected for a research project.</p>
</td>
</tr>
<tr>
<td width="24%" align="right">Title*</td>
<td width="2%">&nbsp;</td>
<td width="24%">[select* Title "Mr." "Mrs." "Ms." "Miss." "Dr." "Prof."]</td>
</tr>
<tr>
<td align="right">First Name*</td>
<td>&nbsp;</td>
<td>[text* FirstName class:textbg]</td>
</tr>
<tr>
<td align="right">Last Name*</td>
<td>&nbsp;</td>
<td>[text* LastName class:textbg]</td>
</tr>
<tr>
<td align="right">Street Address</td>
<td>&nbsp;</td>
<td>[text StreetAddress class:textbg]</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>[text StreetAddress2 class:textbg]</td>
</tr>
<tr>
<td align="right">Suburb*</td>
<td>&nbsp;</td>
<td>[text* Suburb class:textbg]</td>
</tr>
<tr>
<td align="right">State*</td>
<td>&nbsp;</td>
<td>[select* State "" "ACT" "NSW" "NT" "QLD" "SA" "TAS" "VIC" "WA"]</td>
</tr>
<tr>
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Php coding of 2 level drop down

Post by Celauran »

Looks like you want to add the countries as optgroup and their states as options.

Code: Select all

<select name="region">
	<optgroup label="Australia">
		<option value="ACT">ACT</option>
		<option value="NSW">NSW</option>
		<option value="NT">NT</option>
		<option value="QLD">QLD</option>
		<option value="SA">SA</option>
		<option value="TAS">TAS</option>
		<option value="VIC">VIC</option>
		<option value="WA">WA</option>
	</optgroup>
	<optgroup label="New Zealand">
		<option value="AUK">AUK</option>
		<option value="BOP">BOP</option>
		<option value="CAN">CAN</option>
		etc...
	</optgroup>
</select>
Post Reply