Jump to content

[SOLVED] No Properties


The Little Guy

Recommended Posts

If I use createQuery('commentForm') I get an error saying:

    elements has no properties

    for this line:

          for (var i = 0; i < elements.length; i++) {

 

The JS:

function createQuery(form)
{
    var elements = form.elements;
    var pairs = new Array();

    for (var i = 0; i < elements.length; i++) {

        if ((name = elements[i].name) && (value = elements[i].value))
            pairs.push(name + "=" + encodeURIComponent(value));
    }

    return pairs.join("&");
}

 

The HTML:

<form name="commentForm" method="post">
<div style="display:none;" id="comment">
<p><textarea class="profiletbox" name="quickComment" id="quickComment"></textarea></p>
<input type="hidden" name="imgID" value="<?php echo $id; ?>" />
<p><input type="button" onclick="javascript:ajax('/friends/includes/process/postComment','replaceComment');" value="Post Comment" name="submitComment" /></p>
</div>
</form>

 

And finally the AJAX JS:

function ajax(url,query,id){
var contentType = "application/x-www-form-urlencoded; charset=UTF-8";
var ajaxRequest;
try{
	ajaxRequest = new XMLHttpRequest();
} catch (e){
	try{
		ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try{
			ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e){
			alert("Your Browser Doesn't support AJAX.");
			return false;
		}
	}
}
ajaxRequest.onreadystatechange = function(){
	if(ajaxRequest.readyState == 4){
		document.getElementById(id).innerHTML = ajaxRequest.responseText;
		document.getElementById(id).style.display = 'block';
	}
}
ajaxRequest.open("POST", url, true);
ajaxRequest.setRequestHeader("Content-Type", contentType);
ajaxRequest.send(createQuery('commentForm'));
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.