Page 1 of 1

Problems with AJAX

Posted: Thu Mar 27, 2008 5:47 am
by Bennor
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.


Hello,
I am trying to create a simple form where the user writes something in an input box, clicks on a button and the input box becomes what the user have inserted. I am pretty sure I am not doing something right with my ajax and js code so I am pasting it here. I will be happy to hear where am I wrong:

JS

Code: Select all

<!-- 
//Browser Support Code
function ajaxFunction(){
    var ajaxRequest;  // The variable that makes Ajax possible!
    
    try{
        // Opera 8.0+, Firefox, Safari
        ajaxRequest = new XMLHttpRequest();
    } catch (e){
        // Internet Explorer Browsers
        try{
            ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try{
                ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e){
                // Something went wrong
                alert("Your browser broke!");
                return false;
            }
        }
    }
    // Create a function that will receive data sent from the server
    ajaxRequest.onreadystatechange = function(){
        if(ajaxRequest.readyState == 4){
            document.myForm.value = ajaxRequest.responseText;
        }
    }
    ajaxRequest.open("GET", "insert.php", true);
    ajaxRequest.send(null); 
 
function changeText2(){
    var userInput = document.getElementById('userInput').value;
    document.getElementById('title').innerHTML = userInput;
}
 
//-->

~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.

Re: Problems with AJAX

Posted: Thu Mar 27, 2008 10:16 am
by pickle
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:1. Select the correct board for your query. Take some time to read the guidelines in the sticky topic.
Moving to Client-Side.

I always find using document.getElementById() is a simpler method than trying to refer to an element by it's name.

Also, you're not calling your function anywhere.