Jump to content
Sign in to follow this  

drop down value print for dynamic data

Recommended Posts


I am trying to print the value in textbox which is selected from dropdown.

First 2 drop down values am able to print in text box as it is static value.

For third value  , am getting from server.

 how should i print the third after receiving from server.

<!DOCTYPE html>

<select onchange="Choose(this)" >
  <option value="2" >temp1</option>
  <option value="22" >temp2</option>
  <option value="temp3">temp3</option>
  <option value="temp4" >temp4</option>
<input type="text" id="answer" >

function Choose(data) {
    document.getElementById ("answer").value = data.value;

function absolute() {

      var xhttp = new XMLHttpRequest();
      xhttp.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) { 
	      document.getElementById("demo2").innerHTML = this.responseText;        
    xhttp.open("GET", "absolute", true);

    setInterval(absolute, 1000);

 <p  id="demo2"></p>



Share this post

Link to post
Share on other sites

If you're asking how do I update my select to be populated with server values:

  <option value="[serverValue]">[ServerName]</option>

Its not going to be pretty. In this scenario if you wanted to (on the fly) change what this select is you'll need to:
Need to manually change the InnerHTML property, remember which one was selected, stop the refresh while the user has the dropdown open. This is also non-standard and I do not recommend it. (NOTE: If this only needed to be populated on page load, I suggest a preprocessing language like PHP, or otherwise)


If you're asking for a server value based on what is selected, ie select 'temperature' get 60F or whatever it is at the time, then you may want to have a look at sending values. This would be better.

<select name="action">
  <option value="temperature">Temperature</option>
  <option value="height">Height</option>

You would then receive the value from the server based on what you sent to the server.

Here's a good link for that: https://developer.mozilla.org/en-US/docs/Learn/HTML/Forms/Sending_forms_through_JavaScript

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this