You can use and object to store your variables in:
var variables = {};
to add a variable just type:
variables[name] = value;
and to access the value:
variables[name]
Check it out here: jsFiddle
Button 2 reads the value of variables[formid] and button 1 sets formid to submitted