Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Country and State Site Registration Form

Status
Not open for further replies.

WebStuck

Programmer
Joined
Apr 12, 2003
Messages
79
Location
US
Hi,

I have a registration form with country and state fields that need to be filled out. However, the form is international so I only want to bring up the state field, with the corresponding country's states, where appropriate. I have a MySQL table that lists the countries and which countries have states. I have used php to provide a drop down list of countries, but once they choose a country with states then I want a state drop down field to show up with the corresponding states. I think this may require javascript but I wanted to check here first.

Thanks!
Ben
 
It depends on how you do it.

You can use JavaScript solely. In which case your question should be posted in the JavaScript forum.

You can also use a combination of JavaScript and PHP. JavaScript will be used to submit the form when a country is selected. PHP will then determine whether the form was submitted by a user or by JavaScript. If JavaScript submitted the form PHP knows to reproduce the form, but with the state select existent.

Your script can know whether a user or JavaScript submitted the form if you name your submit button. If JavaScript submitted the form, the button will not appear in $_POST in PHP. If the user submitted the form by clicking the submit button, it will.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
How can I do the following:

1. Get the country drop down selection to be sent to a javascript script

2. Have the javascript determine if the country selection has states and then if needed to display the corresponding states for the selected country (this part would be in PHP again)

I am confused on how to use PHP and javascript together and sending data between them.

Thanks!
Ben
 
Again, unless all JavaScript is doing is automatically submitting data to PHP without user intervention, your question starts to fall on the JavaScript side.

PHP can output JavaScript just as well as HTML. It's just print statements.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top