Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6981611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:10:47+00:00 2026-05-27T18:10:47+00:00

First off: I do not want to use JQuery, i know it would make

  • 0

First off: I do not want to use JQuery, i know it would make it easier but it would ravish the porpuse of the thing.
Note: ajaxFunction is the default ajax exemple for a GET/POST

Now, after clicking the function, the first time, it does work and everyrhing gets replaced by the php-echo. The problem is AFTER.

After changing the initia-div (“login-place”) to the next div (“regit”) the javascript function of sregit.onClick = function() does not work.

How do i go around this? Should i create the DOMElement in PHP and use xmlSave(“index.php”)?

initial-div:

<div id="login-place">
    <table id="login-init" name="login-init">
    <tr>
        <td>username</td>
        <td><input type="text" name="user" id="user" /></td>
        <td>password</td>
        <td><input type="password" name="pass" id="pass" /></td>
    </tr>
    <tr>
        <td colspan="2"><input name="login" id="login" type="button" value="entrar" /></td>
    </tr>
    </table>
</div>

the JS code:

            var slogin = document.getElementById("login");
            slogin.onclick = function() {
                //alert("inside."+user.value);
                s = "goforth=1&user="+user.value+"&pass="+pass.value;
                ajaxFunction('4',""+s); 
            }

            var sregit = document.getElementById("regit");
            sregit.onclick = function () {
                alert("inside."+user.value);
                s = "regit=1&user="+user.value+"&pass="+pass.value;
                ajaxfunction('4',""+s); 
            }
    function ajaxFunction(arg,string) {
      var getdate = new Date();  //Used to prevent caching during ajax call
      if(xmlhttp) {

          if (arg==4) {
            nextland = "login-place";
            document.getElementById("all-burps").innerHTML=string;
            xmlhttp.open("POST","session.php",true);
          }
        xmlhttp.onreadystatechange  = handleServerResponse;
        xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

        if (arg==4) {
            xmlhttp.setRequestHeader('Content-length', string.length);
            xmlhttp.send(""+string); 
        }
        }
    }
function handleServerResponse() {
   if (xmlhttp.readyState == 4) {
     if(xmlhttp.status == 200) {
       if (nextland != "login-place") { document.getElementById(nextland).innerHTML=xmlhttp.responseText; } //Update the HTML Form element
       else {
           // alert(xmlhttp.responseText); -> this is true no error up here.
           var thediv = document.getElementById("login-init"); 
           thediv.parentNode.removeChild(thediv); //this happens fine.
           var theplace = document.getElementById("login-place");
           var thelement = document.createElement("div"); //this too.
           thelement.innerHTML=xmlhttp.responseText;  //this too'
           theplace.appendChild(thelement); //this too.

       }
     }

And, the innerhtml.responseText is =

        echo '
            <table id="login-2" name="login-2">
            <h3>o username ' . $username . ' não existe. <a href="#" id="register-link" name="register-link">Queres registar?</a></h3>
            <tr>
                <td>username</td>
                <td><input type="text" name="user" id="user" value="' . $username . '"/></td>
            <td>password</td>
                <td><input type="password" name="pass" id="pass" value="' . $password . '" /></td>
            </tr>
            <tr>
                <td colspan="2"><input type="button" value="entrar" id="regit" name="regit"/></td>
            </tr>
        </table>
        ';

I hope this is enough for anyone to understand my doubt. else i’ll reword it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T18:10:47+00:00Added an answer on May 27, 2026 at 6:10 pm

    The call in the function that does not work says ajaxfunction, whereas the function is called ajaxFunction – Javascript is case sensitive.

    Also, you need to move the declaration of the onclick function for regit to inside the handleServerResponse() function, after the line thelement.innerHTML=xmlhttp.responseText;, because before this line is called, there is no element with id="regit", so the binding of the function won’t work.

    Also, you should terminate the functions declared as element.onclick = function () {} with a ;. Declaring functions in this manner is an assignment statement and as such it requires a semi-colon to terminate it.

    EDIT here is your code reworked so hopefully it does what you want, with some extra bloat removed. I am assuming that xmlhttp, nextland, user and pass have been declared in some code you haven’t posted – have they?

    document.getElementById("login").onclick = function() {
      //alert("inside."+user.value);
      var s = "goforth=1&user="+encodeURIComponent(user.value)+"&pass="+encodeURIComponent(pass.value);
      ajaxFunction(4, s); 
    };
    
    function ajaxFunction(arg, string) {
      //var getdate = new Date();  //Used to prevent caching during ajax call
      // ...but never actually *used* anywhere...
      if (xmlhttp) {
        if (arg == 4) {
          nextland = "login-place";
          document.getElementById("all-burps").innerHTML = string;
          xmlhttp.open("POST", "session.php", true);
        }
        xmlhttp.onreadystatechange = handleServerResponse;
        xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        if (arg == 4) {
          xmlhttp.setRequestHeader('Content-length', string.length);
          xmlhttp.send(string); 
        }
      }
    }
    
    function handleServerResponse() {
      var theplace, thelement;
      if (xmlhttp.readyState == 4) {
        if (xmlhttp.status == 200) {
          if (nextland != "login-place") {
            // Update the HTML Form element
            document.getElementById(nextland).innerHTML = xmlhttp.responseText;
          } else {
            // Remove the old div and add the new content
            theplace = document.getElementById("login-place");
            theplace.removeChild(document.getElementById("login-init"));
            thelement = document.createElement("div");
            thelement.innerHTML = xmlhttp.responseText;
            theplace.appendChild(thelement); //this too.
            // Now add the click handler
            document.getElementById("regit").onclick = function() {
              // alert("inside."+user.value);
              var s = "regit=1&user="+encodeURIComponent(user.value)+"&pass="+encodeURIComponent(pass.value);
              ajaxfunction(4, s); 
            };
          }
        } else {
          // Handle HTTP errors
          alert('HTTP ' + xmlhttp.status);
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First off, I think I'm trying to use Spring incorrectly, but confirmation would be
Now, first off, I want to understand whether or not its better to use
First off, I am not a DBA, but I do work in an environment
First off, I know I can copy "this" on instantiation, but that doesn't work
First off I'm not sure that's the proper title for this question but hopefully
First off, I intend no hostility nor neglegence, just want to know people's thoughts.
First off, I'm not an expert with MySQL queries, and I can't seem to
First off, this is NOT a duplicate of: Turn a C string with NULL
First off, let me start off that I am not a .net developer. The
First off: I know that this isn't reliable for actually checking if I can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.