The Little Guy Posted July 6, 2007 Share Posted July 6, 2007 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 https://forums.phpfreaks.com/topic/58771-solved-no-properties/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.