View Full Version : Saving form values with JavaScript

06-08-2008, 07:20 PM
I'm trying to add another field to a form on a site using Greasemonkey and save the value of whichever radio button is clicked.

Right now I have a "yes" and "no" button with the values 1 and 0.

I have a global variable in my script. formval = 1;

checkRadio() is a function to check which radio button is clicked.

When the user clicks submit, I want it do this: "formval = checkradio[0].value"

However, since at the top the global variable has formval = 1, each time the page is refreshed, formval will go back to 1. I want it to stay 0 if I click 0.

Does anyone have any help?

06-08-2008, 11:08 PM

This is a pretty good tutorial on using cookies to save variables. Keep in mind that this also depends on the user...for instance, do they even have cookies enabled? Also, this is only saving the variable for said user....if another user views the site, it starts with the global declaration for them.