Solved

JQuery Keep div showing after refresh or form fail

Posted on 2014-01-28
5
939 Views
Last Modified: 2014-01-28
I have a piece of JQuery code in a form that shows a specific div, if a radio button is clicked.
$(document).ready(function() {
[b]	$('input[type="radio"]').click(function() {
		if ($(this).attr("value") == "Create New Team") {
			$("#create_new_group").show('fast');
		}	[/b]	
	});

	$('input[type="select"]').checked(function() {
		if ($(this).attr("name") == "group_id") {
		$("#join_group").show('fast');
		}
	});

}); 

Open in new window


in that hidden div are additional form fields that contain a SELECT box.
$(document).ready(function() {
[b]	$('input[type="radio"]').click(function() {
		if ($(this).attr("value") == "Create New Team") {
			$("#create_new_group").show('fast');
		}	[/b]	
	});

	[b]$('input[type="select"]').checked(function() {
		if ($(this).attr("name") == "group_id") {
		$("#join_group").show('fast');
		}
	});[/b]

}); 

Open in new window


Right now if the form is submitted and fails or if the page refreshes, the initial div is closed.  The second piece of code is meant to keep open the initial div upon refresh or form fail, cause the form select choices are sticky.  BUT it does not work.

Any help?  Does this question make sense?
0
Comment
Question by:rgranlund
  • 3
  • 2
5 Comments
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 39815997
The browser does not maintain state betwen pages.  A refresh and submit, both go to the server and anything that must be retained has to be done on the server side in session. if you want the browser to  "remember", then you need to save those memories in cookies (some users may not accept them) and then retrieve them on page load.

Cd&
0
 
LVL 7

Author Comment

by:rgranlund
ID: 39816035
How can I do it with php and making the radio buttons sticky?
0
 
LVL 53

Accepted Solution

by:
COBOLdinosaur earned 500 total points
ID: 39816053
When you go to the server save the values in the session, and then when you re-generate use the values in the session to generate the form, or pass the values as javascript variables, if you are generating the form with client side script.

Cd&
0
 
LVL 7

Author Comment

by:rgranlund
ID: 39816061
I'm to much of a newbie to completely understand that, but thank you anyway!
0
 
LVL 7

Author Comment

by:rgranlund
ID: 39816085
I will start the question over in a different way.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
jQuery Scroll To Top 5 38
jQuery when a text link is clicked? 16 38
Html Newline 7 21
Can't get page to reload 9 10
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question