SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Apr 2003
    Location
    canada
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Post keeping the radio selectin & div after a page refresh

    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 tag after a refresh?

    Code:
    	<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>

  2. #2
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,313
    Mentioned
    178 Post(s)
    Tagged
    8 Thread(s)
    Hi there,

    Quote Originally Posted by robin01 View Post
    how do i maintain the selection, radio button and the div tag after a refresh?
    You'll need to use cookies or some other kind of persistent storage to save the state of the radio button every time it changes.
    Then, when the page loads, you can check for the presence of the cookie and set your radio buttons accordingly.

    I recently wrote a blog post on how to do this with check boxes.
    Maybe it'll help you.

  3. #3
    SitePoint Zealot
    Join Date
    Apr 2003
    Location
    canada
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi pullo,

    THanks for the replay back..
    Not sure if i need to go that far... I just need it to remain where it is so that I can display a status message.


    Quote Originally Posted by Pullo View Post
    Hi there,



    You'll need to use cookies or some other kind of persistent storage to save the state of the radio button every time it changes.
    Then, when the page loads, you can check for the presence of the cookie and set your radio buttons accordingly.

    I recently wrote a blog post on how to do this with check boxes.
    Maybe it'll help you.

  4. #4
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,313
    Mentioned
    178 Post(s)
    Tagged
    8 Thread(s)
    HTTP is a stateless protocol. if the page is refreshed.
    That means that your HTML page will never be able to remember any kind of state about itself, following a page refresh.
    If you want to persist state, you will need to use some kind of client side storage, I'm afraid.

    Or did I misunderstand what you meant by page refresh?


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •