Simple AJAX form doesnt work on iPhone?

I have a simple form on my website which gives the user a instant-quote on our prices. The script doesnt work on the iPhone, which is something I would like it to do just in case someone tries it.

Here is the Javascript:

<script language="javascript">
var XMLHttpRequestObject = false;
if (window.XMLHttpRequest) {
    XMLHttpRequestObject = new XMLHttpRequest();
} else if (window.ActiveXObject) {
    XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
function getQuote()
var obj = document.getElementById('targetDiv');
var name = document.getElementById('name').value;
var email = document.getElementById('email').value;
var length = document.getElementById('length').value;
var period = document.getElementById('period').value;
var url='instantquote.php?name='+escape(name)+'&email='+escape(email)+'&length='+escape(length)+'&period='+escape(period);
if(XMLHttpRequestObject) {"GET", url, true);
XMLHttpRequestObject.onreadystatechange = function()
if (XMLHttpRequestObject.readyState == 1) {
    obj.innerHTML = "<div align='center'><img src='loading.gif' style='padding-top: 25px;'></img></div>";
if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) {
    obj.innerHTML = XMLHttpRequestObject.responseText;

Thanks for any help

I would try doing some standard debugging. You can use alert() or other methods to inspect the values of your variables at strategic parts of your scripts, in order to make sure they contain the values you expect them to have at these points. Make sure to also test your conditional statements to see which ones are true, and which aren’t.

The apple iPhone uses the same type of browser as the Safari web browser, so you may find it easier to troubleshoot on that browser as well.

Others advise that instead of rolling your own ajax, that you use a library that has already solved the issue, but then that wouldn’t be any fun, would it.

Figured it out. In case anyone is interested, Safari does not support sending the form by using a onclick action. You have to use onsubmit in the form tag as well to support all browsers

onsubmit for sending forms - sounds reasonable. Glad to hear that you’ve got it sorted.