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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:52:54+00:00 2026-06-01T09:52:54+00:00

I have a javascript that runs using the onchange event when a user enteres

  • 0

I have a javascript that runs using the onchange event when a user enteres a value into an input box.

The script is

<script type="text/javascript">  
  function showUser(userNumber, str)  
  {  
    if (str=="")  
    {  
      document.getElementById("txtHint" + userNumber).innerHTML="";  
      return;  
    }    
    if (window.XMLHttpRequest)  
    {// code for IE7+, Firefox, Chrome, Opera, Safari  
      xmlhttp=new XMLHttpRequest();  
    }  

    xmlhttp.onreadystatechange=function()  
    {  
      if (xmlhttp.readyState==4 && xmlhttp.status==200)  
      {  
        //document.getElementById("txtHint" + userNumber).innerHTML=xmlhttp.responseText; 
        var responseText = xmlhttp.responseText; 
        var description = responseText; 
        var warehouse = ""; 
        var sellingUnits = ""; 
        if (responseText.indexOf("NOT A VALID") == -1) 
        { 
          description = responseText.substring(12, responseText.indexOf(",Warehouse:"));  
          warehouse = responseText.substring(responseText.indexOf(",Warehouse:")+11, responseText.indexOf(",SellingUnits:"));  
          sellingUnits = responseText.substring(responseText.indexOf(",SellingUnits:")+14);  
        } 

        document.getElementById("whse" + userNumber).innerHTML = warehouse;  
        document.getElementById("txtHint" + userNumber).innerHTML = description;  
        document.getElementById("su" + userNumber).innerHTML = sellingUnits; 

      }  
    }  
    xmlhttp.open("GET","getdata1.php?q="+str,true);  
    xmlhttp.send(); 
  } 
</script> 

and the form is

<form name="orderform" id="orderform" action="newsale.php" method="post">

<table border=1>    

<tr>
<td>Product Code</td>
<td>Description</td>
<td>Warehouse</td>
<td>Selling Units</td>
</tr>
<tr id="r1">  
    <td width=100>
        <input size=10  type=number id=sku1 name=sku1 value="1182" onchange="showUser(1, this.value)">
    </td>
    <td width=280>
        <div align="left" id="txtHint1">&nbsp;</div>
    </td>
    <td width=100>
        <div align="left" id="whse1">&nbsp;</div>
    </td>
    <td width=100>
        <div align="left" id="su1">&nbsp;</div>
    </td>
</tr>
<tr id="r2">  
    <td>
        <input size=10  type=number id=sku2 name=sku2 value="1183" onchange="showUser(2, this.value)">
    </td>
    <td>
        <div align="left" id="txtHint2">&nbsp;</div>
    </td>
    <td>
        <div align="left" id="whse2">&nbsp;</div>
    </td>
    <td width=100>
        <div align="left" id="su2">&nbsp;</div>
    </td>
</tr>
<tr id="r3">  
    <td>
        <input size=10  type=number id=sku3 name=sku3 value="1174" onchange="showUser(3, this.value)">
    </td>
    <td>
        <div align="left" id="txtHint3">&nbsp;</div>
    </td>
    <td>
        <div align="left" id="whse3">&nbsp;</div>
    </td>
    <td width=100>
        <div align="left" id="su3">&nbsp;</div>
    </td>
</tr>
<tr id="r4">  
    <td>
        <input size=10  type=number id=sku4 name=sku4 value="1046" onchange="showUser(4, this.value)">
    </td>
    <td>
        <div align="left" id="txtHint4">&nbsp;</div>
    </td>
    <td>
        <div align="left" id="whse4">&nbsp;</div>
    </td>
    <td width=100>
        <div align="left" id="su4">&nbsp;</div>
    </td>
</tr>
</table>
</form>

So as mentioned, the script works perfectly for the onchange event. I have defined values for each input box, when the page loads I want the script to be called and executed for those values. Once the user changes the values it must rerun for the new value.

I tried putting the following script in the header section of the page, but it is inconsistent in the rows it works for. My skills arent great so I feel I am missing something small.

<script type="text/javascript">  
window.onload = function() { 
showUser(1, document.getElementById("sku1").value);
showUser(2, document.getElementById("sku2").value);
showUser(3, document.getElementById("sku3").value);
showUser(4, document.getElementById("sku4").value);
}
</script>

Any advice is appreciated as always.
Thanks and Regards,
Ryan

  • 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-01T09:52:56+00:00Added an answer on June 1, 2026 at 9:52 am

    Long shot, try this in your existing code. Declare xmlhttp as a local variable to the function.

    <script type="text/javascript">  
      function showUser(userNumber, str)  
      {  
    
        var xmlhttp = null; // line aded.
        if (str=="")  
        {  
          document.getElementById("txtHint" + userNumber).innerHTML="";  
          return;  
        }    
        if (window.XMLHttpRequest)  
        {// code for IE7+, Firefox, Chrome, Opera, Safari  
          xmlhttp=new XMLHttpRequest();  
        }  
    
        xmlhttp.onreadystatechange=function()  
        {  
          if (xmlhttp.readyState==4 && xmlhttp.status==200)  
          {  
            //document.getElementById("txtHint" + userNumber).innerHTML=xmlhttp.responseText; 
            var responseText = xmlhttp.responseText; 
            var description = responseText; 
            var warehouse = ""; 
            var sellingUnits = ""; 
            if (responseText.indexOf("NOT A VALID") == -1) 
            { 
              description = responseText.substring(12, responseText.indexOf(",Warehouse:"));  
              warehouse = responseText.substring(responseText.indexOf(",Warehouse:")+11, responseText.indexOf(",SellingUnits:"));  
              sellingUnits = responseText.substring(responseText.indexOf(",SellingUnits:")+14);  
            } 
    
            document.getElementById("whse" + userNumber).innerHTML = warehouse;  
            document.getElementById("txtHint" + userNumber).innerHTML = description;  
            document.getElementById("su" + userNumber).innerHTML = sellingUnits; 
    
          }  
        }  
        xmlhttp.open("GET","getdata1.php?q="+str,true);  
        xmlhttp.send(); 
      } 
    </script> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a javascript that is executed with the onchange event. onchange=showUser(1, this.value) The
Basically when a user clicks a button I have a javascript code that runs
I have a javascript function that runs every 3 seconds, is there any way
I have JavaScript that is doing activity periodically. When the user is not looking
I have a javascript that displays a generated text into a div: document.getElementById('phrase').innerHTML =
I currently have an ASP Classic script that runs every 15 minutes (via scheduled
I have an interactive JavaScript app that runs through arrays of data. I don't
<a href=tags.php onclick=return popitup('tags.php')>tags</a> I have this line of code that runs the javascript
I have some jQuery code that runs on every $(document).ready() event. I also have
I am using an upload script that runs a function once the file is

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.