Results 1 to 3 of 3

Thread: How To Set Cookie To Radio Button Value

  1. #1
    Join Date
    Mar 2013

    How To Set Cookie To Radio Button Value

    I have a Wordpress blog using FormCraft form builder plugin.

    I need to write cookies with the value of the radio button selected in the form.

    I can't mess with the FormCraft form code itself. I'm told it's possible to write the cookie with Javascript & Jquery whenever a radio button is selected on the page (without changing the FormCraft generated form code), and set the value to the value of the radio button selection.

    Anyone know how this is done? And/or have some code examples of how it would be done?
    Last edited by Sage; 08-26-2013 at 04:24 AM.

  2. #2
    Join Date
    Sep 2008
    Jackson MS
    This code can read and return the selected radio button:
    function readStrum() {
      var sel = document.getElementsByName("A1");
      for (var i=0; i<sel.length; i++) {
        if (sel[i].checked == true) return i;
    function readRadio(i) {
      var sel = document.getElementsByName("S"+(6-i));
      for (var i=0; i<sel.length; i++) {
        if (sel[i].checked == true) return i;
    The first function reads a strum option ("A1") while the second one reads a specified guitar string. If you need to save more than one thing, use a specific character as a delimiter so a split command can separate them for you.
    var my_cookie = "";
      my_cookie += document.nwcform.NoteDur.selectedIndex + "|";
      my_cookie += ((document.nwcform.bIsDot.checked) ? 1 : 0 ) + "|";
      my_cookie += readStrum() + "|";
      my_cookie += ((document.nwcform.selAll.checked) ? 1 : 0 ) + "|";
      my_cookie += ((document.nwcform.FretQwikCh.checked) ? 1 : 0 ) + "|";   etc
    This is from guitar.htm.


  3. #3
    Join Date
    Mar 2007
    If you can't change the form you need a way to identify it. Does the form have an ID?

    What is the name of the radio button group?
    Where used, return should be executed unconditionally and always as the last statement in the function.

    That's my signature, it's not part of the damn post!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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