cookies - Control link preferences with radio button controls and jquery -
For any link with a particular CSS class, I would like to control whether the links are open in the same window , New window or a pop-up (using onclick), based on the user's selection from the radio button - and then by saving this option in the cookie (using all jQuery). Does anyone know how to accomplish this?
How would I do this ... (You will need):
& lt; Script language = "javascript" & gt; $ (Function () (cookie ('link_pref')) {var link_pref = $ .cookie ('link_pref'); $ ('# link_options_form: radio [value = "' + link_pref + '"]') ART ('check', 'check');} $ .cookie ('link_pref', $ ('# link_options_form: radio: check'). Val (), {expires: 0}); $ ('# link_options_form: radio ('' Click ''). Bine ('click', function) ($ .cookie ('link_pref', $ (this) .val (), {expires: 0});}); $ ('Bind ( 'Click', function) (var link_pref = $ .cookie ('link_pref'); var href = $ (this) .attr ('href'); var link_txt = $ (This) .text (); switch (link_pref) Case 'pop': window.open (href, link_txt, 'width = 640, height = 480, toolbar =' ''; ' Yes, location = yes, directory = yes, position = yes, man Uber = yes, scrollbar = yes, copyhearty = yes, resizable = yes'); return back; case 'greybox': // other options found here: // http://orangoo.com/labs/greybox/advance_usage.html GB_show (link_txt, href); the description is false; Default: $ (this) .attr ('target', '_self'); Back true; }}); }); & Lt; / Script & gt; & Lt; Form id = "link_options_form" & gt; & Lt; Label & gt; & Lt; Input type = "radio" name = "link_pay" value = "equal" /> Open in the same window & lt; / Label & gt; & Lt; Label & gt; & Lt; Input type = "radio" name = "link_pay" value = "new" /> Open in a new window & lt; / Label & gt; & Lt; Label & gt; & Lt; Input type = "radio" name = "link_pection" value = "pop" /> Open in a pop-up window & lt; / Label & gt; & Lt; Label & gt; & Lt; Input type = "radio" name = "link_options" value = "greybox" /> Open in Graybox & lt; / Labels & gt; & Lt; / Form & gt; Edit: Sorry I did not check it for the first time. I had some typos and I forgot to start with the cookie (sorry). I have tested it and now it works with your HTML, use the newly edited code above; -)
Edit 2: I have added a direct link to the cookie plugin, just because you are not using it properly, for any reason.
Edit 3: Personally, I can not set the radio button in JavaScript as a check ... you use the same cookie in your server-side language Who can trust me? But, I have provided a new method which should work in my new edited code.
Edit 4: The initial setting of the checked radio button bug has been fixed. In fact it really should work really right now. O_0
Comments
Post a Comment