aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Question on .submit and reloading form values AFTER the submit button is clicked Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Question on .submit and reloading form values AFTER the submit button is clicked" Watch "Question on .submit and reloading form values AFTER the submit button is clicked" New topic
Author

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

Melinda Savoy
Ranch Hand

Joined: Jun 21, 2005
Posts: 386

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

Joined: Jan 10, 2002
Posts: 60045
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15286
    
    6

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.


GenRocket - A Test Data Generation Platform
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15286
    
    6

Great minds...
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60045
    
  65

Melinda Savoy
Ranch Hand

Joined: Jun 21, 2005
Posts: 386

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

Joined: Jun 21, 2005
Posts: 386

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

Joined: Jan 10, 2002
Posts: 60045
    
  65

Please make sure that you use this as an opportunity to understand the fundamentals of the HTTP request/response cycle.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question on .submit and reloading form values AFTER the submit button is clicked
 
Similar Threads
Question on making a dropdown list read-only
Question on using jQuery's .attr AFTER form is submitted
Question on jQuery ajax functionality & troubleshooting called bean in JSF page
Newbie question using jquery validator plugin on my JSF page
trying to populate hidden field on my JSF form using jQuery