Search code examples
javascripthtmljqueryradio-buttonchecked

Radio Buttons Switch Checked php


My site is like a search engine with 2 types of search. Type 1 Type 2. I just dont know how to do it when someone come to my site the default checked type to be Type 1 and if it choose Type2 then remain Type2 for the visitor even if the page is refreshed. What i need exactly is like sample from here.

js

$(function() {
        $( "#radio" ).buttonset();
    });​

html

<form>
    <div id="radio">
        <input type="radio" id="radio1" name="radio" /><label for="radio1">Choice 1</label>
        <input type="radio" id="radio2" name="radio" checked="checked" /><label for="radio2">Choice 2</label>
        <input type="radio" id="radio3" name="radio" /><label for="radio3">Choice 3</label>
    </div>
</form>

I want to be able to switch the checked="checked" from a radio to another or something like this i think. Really don't know. But i think it has to do something with php or javascript.


Solution

  • You would need to cache/store the set option somewhere (cookie, database, memcache(d), redis, etc.) and load using the user's ID. This will also have to be handled in Javascript as it involves the client-side.

    Cookie Reference: https://developer.mozilla.org/en-US/docs/DOM/document.cookie

    For memcache(d), redis, SQL, file storage:

    AJAX Reference: https://developer.mozilla.org/en-US/docs/AJAX