I've got a problem figuring out how to pass a variable to parameter of the ajaxForm()
function. I am getting templatedir path from hidden form field after clicking on form button in jQuery (this works great) and I can pass it to other function but not to the ajaxForm()
parameter:
var templatedir;
// Get variable of templatedir
$('form#contact input[type="submit"]').on('click',function(){
templatedir = $('input[name=templatedir]').fieldValue();
});
// Validate Form
function validateform(formData, jqForm, options) {
...
// IF I CALL TEMPLATEDIR HERE IT WORKS
}
// Send to PHPMailer
$("form#contact").ajaxForm({
url: templatedir, // IT DOESNT WORK HERE
type: 'post',
beforeSubmit: validateform,
target: '#msg',
clearForm: true
});
I tried the solution from this answer (How do i pass variables between functions in javascript) as you can see but it doesn't work.