Jump to content
Sign in to follow this  
s_avinash_s

drop down value print for dynamic data

Recommended Posts

Hi 

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>
<html>
<body>

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


<script>
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);
    xhttp.send();
    }

    setInterval(absolute, 1000);
</script>


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


</body>
</html>

 

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:
Scenario:

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

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>
</select>

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...