I have am HTML form in a PHP page. The form has various inputs. One of the inputs has an onchange event:
<input size=10 type=number id=sku1 name=sku1 onchange="showUser(1, this.value);showWhse(1, this.value)">
This calls the following function:
<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.substring(12, responseText.indexOf(",Warehouse:"));
var warehouse = responseText.substring(responseText.indexOf(",Warehouse:")+11, responseText.indexOf(",SellingUnits:"));
var 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>
This works 100%. if however, the input is populated by a session variable, and the page is refreshed, how can I get the script to execute again onload, without an onchange event?
so when the page is first visited, id the input has a value, execute the script?