/    Sign up×
Community /Pin to ProfileBookmark

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?

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@wbportAug 27.2013 — This code can read and return the selected radio button:
[CODE]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;
}
}[/CODE]

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 [B]split[/B] command can separate them for you.
[CODE]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[/CODE]

This is from guitar.htm.

HTH
Copy linkTweet thisAlerts:
@Logic_AliAug 28.2013 — 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?
×

Success!

Help @Sage spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...