I assume this is a Marketo-hosted LP. Otherwise, from your brief description, you probably have a race condition causing the code to only work some of the time.
Yes, it's a Marketo-hosted LP with the script attached to it.
Below's the sample script we used:
<html>
<head>
<script type = "text/javascript">
MktoForms2.whenReady(function (form) {
// Put your code that uses the form object here
var email = document.getElementById('Email').value;
var first_name = document.getElementById('FirstName').value;
var last_name = document.getElementById('LastName').value;
var company = document.getElementById('Company').value;
var image = document.getElementById('loading_gif');
var form = MktoForms2.getForm(####);
form.onSuccess(function (values, followUpUrl)
{ window.top.location.href = followUpUrl; return false;
});
if (email != "" && first_name != "" && last_name != "" && company != "")
{
form.getFormElem().hide();
document.getElementById('loading_gif').style.display = "block";
form.submit();
}
else
{
}
});
</script>
</head>
<body>
<img id='loading_gif' src="image_url" style="display: none;">
</body>
</html>
The code looks safe as far as race conditions, since you're using the Forms 2.0 API. But it's making unnecessary (and theoretically risky, though not in the present 2.0 release) use of document.getElementById. It should use form.getValues().Email, etc.