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 7831257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T11:38:47+00:00 2026-06-02T11:38:47+00:00

Hei, I’m trying to fill a textfield declared in a jsp file with some

  • 0

Hei, I’m trying to fill a textfield declared in a jsp file with some text after calling a servlet using Ajax. The xmlhttp.responseText contains the text returned by the servlet, but the input with the message id is not filled with that text and I don’t know why. Any suggestions? The code used is below.

function ajaxFunction() {
  if(xmlhttp) { 
   var txtname = document.getElementById("txtname");
    xmlhttp.open("POST","getname",true); //getname will be the servlet name
    xmlhttp.onreadystatechange  = handleServerResponse;
    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlhttp.send("txtname=" + txtname.value); //Posting txtname to Servlet
  }
}

function handleServerResponse() {
    //alert(xmlhttp.readyState);//ok    
   if (xmlhttp.readyState == 4) {
       alert(xmlhttp.status);
     if(xmlhttp.status == 200) {
         alert(xmlhttp.responseText); // this is ok
         document.getElementById("message").innerHTML=xmlhttp.responseText; // doesn't work
       //document.myForm.message.innerHTML=xmlhttp.responseText; //neither
     }
     else {
        alert("Error during AJAX call. Please try again");
     }
   }
}
</script>

<body>
  <form name="myForm" method="POST" action="/ajjax/getname">
    <table>
      <tr>
        <td>Enter Name</td>
        <td><input type="text" name="txtname" id="txtname" /></td>
      </tr>
      <tr>
        <td colspan="2"><input type="button" value="Submit" onclick="ajaxFunction();" /></td>
      </tr>
    </table>
    <input type="text" name="message" id="message" />  
  </form>
</body>
</head> </html>
  • 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-06-02T11:38:49+00:00Added an answer on June 2, 2026 at 11:38 am

    Try this:

    document.getElementById("message").value = xmlhttp.responseText;
    

    <input/> fields have value attribute, innerHtml won’t work (at least as expected).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hei. I am using the POST method for sending some information from a JSP
Hei I’m trying to learn Linq to SQL and wondering if somebody can suggest
hei, Using Linq to SQL (ala NorthWind database for example): How to select all
Hei there, I started using ajaxForm plugin, having the form statement like this: <form
Hei there, right now I'm trying to connect two seperate Subapps with one view.
Hei Iam trying to find out how to pring graphs in .net platform .
Hei guys, I'm trying to help my friend to design database tables. It is
Hei , I'm trying to verify if my username and password from my xml
Hei guys i have this JQuery Ajax call from my view and it looks
Hei! I need to optimize some matrix multiplication code in c, and I'm doing

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.