2

My form ID is "requestquote". When I submit the form I am receiving an error in the console that ('formSub has no value'). The form process is being completed via my PHP action file but I need this bit of javascript to run as well. Any suggestions would be appreciated.

<script> 
_opt.push(['instrument','requestquote']);

var formSub = $('requestquote');
console.log(formSub);

formSub.submit(function(){

_opt.modifyFormParameters = function(parameters){

parameters["_orig_action"] = document.getElementById("_orig_action").value;
parameters["_opt_vid"] = document.getElementById("_opt_vid").value;
parameters["_opt_visit"] = document.getElementById("_opt_visit").value;
parameters["_opt_cid"] = document.getElementById("_opt_cid").value;
parameters["_opt_url"] = document.getElementById("_opt_url").value;
parameters["_opt_paget"] = document.getElementById("_opt_paget").value;
parameters["first_name"] = document.getElementById("name").value;
parameters["company"] = document.getElementById("company").value;
parameters["website"] = document.getElementById("url").value;
parameters["email"] = document.getElementById("email").value;
parameters["phone"] = document.getElementById("phone").value;

return parameters;
};
_opt.push(['submit', 'requestquote']);
_opt.the_form = this;

setTimeout(function(){ _opt.the_form.submit(); } , 1000);
return false;
});
</script>

Here is the Form Code

<form id="requestquote" action="/quote-process/contact_pr_EPH.php" method="post">
5
  • Make sure to run this after defining the element in HTML. Other than that there's not enough information. Commented Sep 10, 2012 at 14:47
  • 1
    can you please add the code of the <form>? Commented Sep 10, 2012 at 14:47
  • The script is the last thing within the body in footer.php Commented Sep 10, 2012 at 14:50
  • 2
    I think you need to provide a complete minimal test case that fully demonstrates the problem. Commented Sep 10, 2012 at 14:56
  • Wait, you write that you get an error when you submit the form. That would suggest that the problem is somewhere inside the onsubmit handler. I think you'll need to show us more code if you want us to be able to help. Commented Sep 10, 2012 at 15:03

4 Answers 4

3

If it's the ID of the form then it should be :

$('#requestquote'); or even $('form#requestquote');.

$() does more than just GetElementByID. Read up on the jQuery (truly Sizzle) selector(s): http://api.jquery.com/category/selectors/

Sign up to request clarification or add additional context in comments.

1 Comment

So obvious and yet so hard to detect ;)
0

This is usually caused by one of:

  • Not having an element with the given id in the document at all
  • Not having an element with the given id in the document at the time the script is run (e.g. when the <script> appears before the <form> in the source order)

You can deal with timing issues by rearranging the source order, or by wrapping the gEbId call in a function that gets called onload / ondomready / otherwise after the form element exists.

1 Comment

I have added an on page load jQuery function .. still receiving null for 'formSub'.
0

In the third line of your script, var formSub = $('requestquote'); should be var formSub = $('#requestquote');

The # indicates to jQuery that you want to search for an id rather than a tag name.

Comments

0

It's hard to tell from the example code. But could the JavaScript be executing before the requestquote element has been made?

Something like an onLoad event can be used to make the JavaScript execute after all the HTML elements have loaded.

1 Comment

He already told that "The script is the last thing within the body in footer.php"...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.