0
<form action="#" Method="post">
<input type="radio" name="cakes" value="blackforest">
<input type="radio" name="cakes" value="darkforest">
<input type="radio" name="cakes" value="vanila">
<input type="submit" value="submit">
</form>

Quoted Text Here

here what the thing is i selected a radio button from those choices.
now i did refreshing the page.
the selected radio button will not display as checked after refreshing.so even page refreshing done i have to display the button as checked when it was selected by the user before page refreshing.
so suggest a good one to keep the checked radio buttons as checked even after page refreshing.
thanks to all

5
Contributors
7
Replies
8
Views
4 Years
Discussion Span
Last Post by diafol
0

Store the selected one in a session variable, and use that to select the right radiobutton when generating your page.

0

Start a session and store the selected option in a session object.

session_start();
$_SESSION['cake'] = $_POST['cakes'];

Then check if the current radiobutton is equal to the session variable, if it is set it to "selected".

<input type="radio"
       name="cakes"
       value="blackforest"
       <?php if ($_SESSION['cake'] == "blackforest") echo "selected=\"selected\""; ?> />
0

Hi,

In html 5, if my memory can still serve me well, there is a function called "web storage" I am not pretty sure of the name, because I can't find a good search result on my desktop. However, this function can save the checked or any inputted data on the form. The browser can refreshed or can visit another page, but when you go back that page, you selection is still there as if the browser never left the page.

This question should be posted in javascript section, but since that you are already here, let's try to deal with this matter accordingly..

Copy these codes and modify it to your needs

    <!DOCTYPE html>
    <!-- doctype above is the minimum requirement for the html5 standard -->
    <head>
    <script >

    $(document).ready(function () {
        function init() {
            if (localStorage["cakes"]) {
                $('#cakes').thisradio(localStorage["cakes"]);
            }

        }
        init();
    });

    $('#radioselected').keyup(function () {
        localStorage[$(this).attr('cakes')] = $(this).thisradio();
    });

    $('#thisForm').submit(function() {
        localStorage.clear();
    });
    </script>
    </head>
    <body>

        <form id="thisForm" action="#" Method="post">
        <input type="radio" name="cakes" id="radioselected cakes" value="blackforest">Black Forest<br/>
        <input type="radio" name="cakes" id="radioselected cakes" value="darkforest">Dark Forest<br/>
        <input type="radio" name="cakes" id="radioselected cakes" value="vanila">Vanilla<br/>
        <input type="submit" value="submit">
        </form>



    </body>
    </html>

reference

Edited by veedeoo: info added

0

yes diafol.wat u said was correct local storage was not working in chrome/opera..any other good suggestions beyond this

0

i'm worked,even with sessions.but my problem was not solved.may be my implementaion is wrong i think so.but how can we store a value in seesions using onclick function.
i hve to store the values wheb ever user was selected.is it possible storing a values in php sessions using onclick/select functions..

or tell me a another better way to do this...or suggest a code to block the page refreshing

0

No, you can't access sessions this way. In order to do so, you need to use Ajax. Have a look at jQuery for easy ajax.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.