<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

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

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\""; ?> />

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

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

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

Member Avatar for diafol

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.