I'm storing the value of a specific form element as a variable. This same value is used in multiple functions.
function one() {
var selectedRole = $('#RegistrationRole_ID').val();
}
function two() {
var selectedRole = $('#RegistrationRole_ID').val();
}
I'd like to make this a global variable so I don't have to keep selecting it in each of my functions. So my question is, am I able to still get the value correctly if I declare the variable outside of my document ready block?
<select id="RegistrationRole_ID">
<option value="1">one</option>
</select>
I think I might have answered my own question...it's possible that the value may change from when the document is loaded. Really, what I am trying to do is remove duplicate code, where I get the value of the element multiple times. Do you have a suggestion for this?