2

I'm having a problem where i have two select boxes, one for office location and the other for the employees that are in that office. I've got it working fine where if i select an office it grabs the data for the employees in that office in the next drop down and enables that select box.

What i'm having trouble figuring out is on a failed server validation (i.e., didnt select an employee or didnt fill out an input field) have the chained select box remain active with the selection they had previously selected.

Any help would be greatly appreciated!

2
  • Your question is a little ambiguous. What is the problem? Commented Jun 10, 2011 at 20:34
  • How I keep the chained select box enabled and using PHP select the value they had if my server side form validation fails? It always goes back to disabled and no values in it. Commented Jun 10, 2011 at 20:36

2 Answers 2

1

You should consider to use a javascript framework like jQuery and php ajax call to validate the first selection and then consequently populate the second one. In such a way you have not to reload the entire page, only change select contents. There are many samples which can be found googling the web. Check this tutorial for example : http://www.9lessons.info/2010/08/dynamic-dependent-select-box-using.html?m=1

Sign up to request clarification or add additional context in comments.

1 Comment

I basically have that exact script setup. I have a few additional input text fields that i added. If one of those fields fails server side validation, how do i keep the second select box selected on what it was?
0

If I'm understanding you correctly, you need to validate BEFORE you submit. Leverage jQuery and check the form fields; see that the server will validate before you post the form.

6 Comments

I'm trying to avoid client side validation in case they have javascript turned off.
@Chris that contradicts your chaining logic. If they have Javascript turned off, how do you expect it to "grab the data" ?
I guess to make life easier then i'll just implement client side validation. Do you have any ideas if i also have server side validation and one of those fails to reload the chained select box to the users selection?
@Chris yes; when the POST data is sent to the validating page, run the check against your data source to see if it is valid. If not, re-build the form and use the POST data as dynamic defaults for the form elements.
You would do that by posting the form page to itself. If it is successful, then you'd redirect to a success page. If not, you'd use the POST data and jQuery to select the boxes.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.