Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question on .submit and reloading form values AFTER the submit button is clicked

 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Here is my code:



 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64606
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great minds...
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64606
86
IntelliJ IDE Java jQuery Mac Mac OS X
 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got my problem resolved and working. .load() in jQuery did not resolve my issue. I went back to the onload javascript method and was able to resolve selecting the option based on a hidden value captured after the page was reloaded and do what I needed to with it.

Again, appreciate the replies and help.

Regards.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64606
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please make sure that you use this as an opportunity to understand the fundamentals of the HTTP request/response cycle.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic