This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I am using jQuery 1.4.3 and have a newbie question.
In the following .submit function, I grab the value of the selected option in the facilityCodes dropdown list after I click the submit button and then during the submit function, select the facilityCode again in the dropdown list and then disable the list so that the user cannot change it. However, the situation is when I reload the page after the submit button is clicked the dropdown defaults to the first option and the list is enabled. I apparently am not understanding how .submit works so that I'm selecting the option I'm defining in my code and then disabling the list AFTER the page reloads. My question is what am I doing wrong? Am I using the wrong event?
Any help/direction would be greatly appreciated. Thank you.
Anything you do in the current page will be completely lost when the page reloads. You need to handle any changes you want to make in the page in the new instance of the page.
When you submit the page, an HTTP request is sent to the server, which returns a response with a new page. The fact that it is the same page as before is completely moot. It's a brand new page to the browser.
In other words. Once you submit, your work is done. Nothing you do after that will make any difference as to how the next display of a page (even the same one) is handled.
If I'm understanding your question correctly, the answer is that this is expected behavior. All you're doing by supplying the submit event is basically doing something like "before I submit this, I want this to happen". Once the form is submitted, and the page refreshes, that function doesn't run again until it is triggered. So in your case, you would need to have some server side logic that translates down to the page that tells the select which option should be selected and that is should (or should not) be disabled.
Thank you both for your time in replying. Let me ask my question differently and how I can accomplish what I need to do.
If there is an error when the user clicks on the submit button, the page is reloaded with the errors denoted on the page in the .submit function when validating fields. The issue that I'm fighting is that when the page reloads I need to be able to set the option in the dropdown and then disable the dropdown so that the user cannot change it because originally it was programmatically set before the page was submitted.
I set a hidden value for the dropdown and in viewing the source code in the browser, I noticed it was STILL SET when the page reloaded. Can I accomplish what I explained above by using the .load() as indicated below:
Again your time and response would be appreciated. Thank you.