I have a javascript that I downloaded off the net. This works great. My problem is I now require to use this same script but on three instances on the page? how can I duplicate or edit this javascript code in order to acheive this.
To give you a background, I have a dropdown list, that onchange calls the below function to populate a table with mysql data without page refresh. the script shows info from another page, getpersonsformedical.php.
I now have two other pages that I want to show on the same page using the same javascript. namely getjobsformedical.php and getrisksformedical.php.
Any help would be appreciated. (apologies my javascript is not that great).
Can I just duplicate the code in another script tag? but then how do I call multiple onchange events for a single tag onclick. All three of these pages must be called from the single onclick.
I understand that there are other ways of doing this but if we could stivck to this methodology it would be appreciated.
To clarify, I need one onchage event to display three seperate php pages(with mysql data) in three seperate .
UPDATE WITH ANSWER
Thanks to dystroy, complete working script is:
<script>
function showUser(userNumber, str, target, page) {
if (str=="") {
document.getElementById(target + userNumber).innerHTML='';
return;
}
var xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById(target).innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET",page+"?q="+str,true);
xmlhttp.send();
}
function showThreeSections(userNumber, str) {
showUser(userNumber, str, 'a', 'getpersonsformedical.php');
showUser(userNumber, str, 'b', 'getjobsformedical.php');
showUser(userNumber, str, 'c', 'getrisksformedical.php');
}
</script>
outputted to divs:
<div align="left" id="a"><font color=gray>Person Assignment will be shown here</font></div>
<div align="left" id="b"><font color=gray>Person Jobs will be shown here</font></div>
<div align="left" id="c"><font color=gray>Person Risks will be shown here</font></div>
Thanks and Regards, Ryan
showUsertakes parameters. Just duplicate the<SELECT NAME=medcondition3 id=medcondition3 onchange="showUser(1, this.value)">.ext/mysql(themysql_*family) is deprecated. Please use something else instead.