SunTzu Posted December 29, 2006 Share Posted December 29, 2006 Hi to All,I have spent whole day trying to figure out how to populate a drop down list according to the value of another drop down list.I have "departments" and "positions" so when i select a dept. from the first drop down i want the respective positions to populate the other. The problem here is that i need to do that before "Posting" the form which would resolve easily my problem.I tried to use JavaScript but in vain as JS is used at the client side while PhP at the server side.Please advise ...thnx Link to comment Share on other sites More sharing options...
yoshida Posted December 30, 2006 Share Posted December 30, 2006 One thing you need to understand is that php is a server side script. It will not do anything unless the user (read: the function a user is using) is making a request.What you can do is have the user select a department, have that saved to a session (or propagate it) when the user hits 'next' and perform a query on the db to select all positions where department = $department. The result will be 'looped' into a new dropdown.A combo of js and iframes is a realistic one too, but you're going to find iframes is a world of hurt on itself.There's more solutions available on the web. They're not easy (and usually require client sided scripting) but they're well worth the effort. Link to comment Share on other sites More sharing options...
SunTzu Posted December 30, 2006 Author Share Posted December 30, 2006 Thanks yoshida ..I will try to use Javascript to reload the page with the parameter dept like self.location = xx.php?dept="value" and then get it with $_GET[].Do you think that AJAX would help here ? Link to comment Share on other sites More sharing options...
yoshida Posted December 30, 2006 Share Posted December 30, 2006 Do you think that AJAX would help here ?It definitely would. But it's worlds away from php. Link to comment Share on other sites More sharing options...
CStrauss Posted December 30, 2006 Share Posted December 30, 2006 PHP for the win (just want to say that ) Link to comment Share on other sites More sharing options...
yoshida Posted December 30, 2006 Share Posted December 30, 2006 PHP for the win (just want to say that )Second! (just kidding, I think js and xml have a great future, they're just frog king hard to master. Enter PHP) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now