One more thing:
>><input type="submit" name="submit" value="Send"></td>
NEVER name anything (function or html element) "submit". It is a "reserved" method for the form object. Naming something else "submit" will likely cause a name collision that will be extremely difficult to debug. Since javascript IS case sensitive, you can (if you want) use name="Submit" [uppercase "S"], but do NOT use "submit".
Main Topics
Browse All Topics





by: hieloPosted on 2009-11-05 at 07:46:15ID: 25750697
A. on your code you have: name)
(name)
Name()] returns a LIST/"array" of elements, NOT a single element, but the way you are using here: "user");
("user")[0 ];
lue) + "&name=" + encodeURIComponent(name.va lue) + "&company=" + encodeURIComponent(company .value) + "&email=" + encodeURIComponent(email.v alue) + "&message=" + encodeURIComponent(message .value) );
Content-Ty pe', 'application/x-www-form-ur lencoded') ; lue) + "&name=" + encodeURIComponent(name.va lue) + "&company=" + encodeURIComponent(company .value) + "&email=" + encodeURIComponent(email.v alue) + "&message=" + encodeURIComponent(message .value) ; Content-Le ngth', params.length);
document.getElementByName(
but it should be:
document.getElementsByName
Notice the "s" before "ByName"
B. that function [document.getElementsByTag
var user = document.getElementByName(
makes me believe that you think you are assigning a reference to a single element but you are NOT. After that statement executes the variable "user" doe NOT hold a reference to the "user" input field. It holds a reference to an "array" that consists of one element. It is that one element within the array that IS the reference to the input field you need. So you need to change that to:
var user = document.getElementsByName
Personally, I prefer to use the document.getElementById() function since that DOES return a SINGLE element at most, but you will need to give your <input> elements a unique id:
C. You need to encode the VALUES of the data you are sending. Notice I wrote VALUES, not "field names". So this:
xmlHttp.send("user=" + user.value + "&name=" + name.value + "&company=" + company.value + "&email=" + email.value + "&message=" + message.value);
should actually be:
xmlHttp.send("user=" + encodeURIComponent(user.va
D. BEFORE you invoke the send() method, you need to set some needed headers. You are CORRECTLY setting the Content-Type header, but you ALSO NEED the Content-Length Header for POST requests. The value of this Content-Length header should be the length of the data you are sending to the server. So if you take what is in the send() method above[C] and assign it to a variable, you can use the lenght of that string to set your header, and then use that same variable for the send() method:
...
xmlhttp.setRequestHeader('
var params="user=" + encodeURIComponent(user.va
xmlhttp.setRequestHeader('
xmlhttp.send(params);
...
...