Jump to content

jquery hide/show div after refresh


learningPHP1

Recommended Posts

Hello everybody,

 

I'm working on a script which has 2 div tages controled by 2 radio buttons and using jquery to hide/show the div tags based on the users selection.

 

Like to have..

if a user selects one of the radio button i like to maintain the selection radio button and the div tag if the page is refreshed.

 

Problem:

if the user selects the second div tag and if the page refreshes the radio button and the div tag returns to the initial setup which is going back to the first radio button and div tag.

 

how do i maintain the selection, radio button and the div tage after a refresh?

	<script type='text/javascript'>
		$(document).ready(function()
		{	$("#DivB").hide();
			$('input[name="myproject"]').change(function()
			{	if($(this).val() == "A")
				{	$("#DivA").show();
					$("#DivB").hide();
				}
				else
				{	$("#DivA").hide();
					$("#DivB").show();
				}
			});
		});
	</script>	
	
	<div style ="border:1px solid black;">
		<form action='<?php echo $_SERVER['PHP_SELF']; ?>' method='POST'>
			<div  id="div1">
				<input type='radio' name='myproject' value='A'  checked="checked" <?php echo (isset($_POST['myproject']) && $_POST['myproject'] == 'A') ?  'checked':'';      ?> />Have projectID
				<input type='radio' name='myproject' value='B' <?php echo (isset($_POST['myproject']) && $_POST['myproject'] == 'B') ?  'checked':'';                         ?> />Lost projectID<br />
			</div>
			
			<hr />
			<div id='DivA'> 
				projectID:<br /> <input type="text" name="proId"><br />
				email:    <br /> <input type="text" name="email"><br /><br />
				<button name="btn_prj_info">View project status</button> <br />		
			</div>
			
			<div id='DivB'>
				Email: <br /> <input type="text" name="emailR"><br /><br />
				<button name="btn_email">Email information</button> <br />	
			</div>
		</form>
	</div>
Link to comment
Share on other sites

When a radio button is selected, set a cookie or use local storage to store the value of the radio selected. Then when the page refreshes, check to see if the cookie/local storage variable is set, and then use that to set the radio button value.

 

That would be the theory to get the job done.

 

Denno

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.