$( document ).ready(function() {
function geteverthing() {
var fonttype = $('#font').attr('class');
var sizetype = $('#size').attr('class');
var colourval = $( "#colourselect option:selected" ).val();
var imageval = $( "#imageselect option:selected" ).val();
}
function imageupdate() {
geteverthing();
// Do some stuff with these variables
}
function colourupdate() {
geteverthing();
// Do some stuff with these variables
}
function fontupdate() {
geteverthing();
// Do some stuff with these variables
}
});
I have several functions which use the same variables. The variables change value depending on what functions are called when using a form.
In the previous set up I had the variables called within each function and everything worked fine.
I then tried to bring the variables outside all the functions within document ready. This resulted in calling variables which weren’t up to date when interacting with the form.
I then tried to put the variables in another function and call that function within each of the other functions but I get a variable not defined.
For cleanness I want to only have these variables defined once and reference them, can someone tell me what I am doing incorrectly?
Thanks for your time.