Form submits correctly in Chrome / FF but fails completely in IE / Safari
I have a form with a css submit button. When the submit button is clicked, I call a function that does:
document.forms["request"].onsubmit();
What should happen is that the onsubmit method should be run. This works correctly in Chrome / FF, but for some reason IE / Safari will bypass the onsubmit function and just add the "address =" parameter to the url as if it were submitting the form and ignore the onsubmit function. Here is the code for the form:
<form id="request" method="get" onsubmit="addLocation(this.address.value); return false;">
<br>
<label style="position:relative;left:5px;" for="address">Enter an intersection or address:
</label>
<br>
<br>
<input style="height:35px; width:300px;position:relative;bottom:1px;left:10px;" id="address" name="address" class="required address"/>
<a style="float:right;right:120px;position:relative;" class="button" onclick="submit();">
<span>Submit Request
</span>
</a>
</form>
and then some relevant js functions:
function addLocation(address) {
if (geocoder) {
geocoder.getLocations(address, function (point) {
if (!point) {
alert(address + " not found");
} else {
if (point.Placemark[0].address != submittedString) {
submittedString = point.Placemark[0].address;
addRow(point.Placemark[0].address);
req = "addrequest?truck=" + "coolhaus&address=" + point.Placemark[0].address;
alert(req);
addRequest(req);
request.onreadystatechange = function () {}
}
}
});
}
}
function addRequest(req) {
try {
request = new XMLHttpRequest();
} catch (e) {
try {
request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
alert("XMLHttpRequest error: " + e);
}
}
request.open("GET", req, true);
request.send(null);
return request;
}
You can check the form here:
http://la.truxmap.com/request?id=grillmastersla
Many thanks!
source to share
Don't call your function "submit", there is already a method on the form with that name, so it might conflict with that.
This is the method submit
you can call to submit the form, not the event onsubmit
. So your code for submitting the form should be:
document.forms["request"].submit();
source to share