dscxz dscxz - 1 year ago 90
Javascript Question

i can't call 2 functions from onchange event

I have to call an ajax function as well as call an additional function to get another value by giving the above text field as the input. I want to get the return ,form that function.
Here is the code I have used to call the 2 functions, but only the first function ajax(this) is only working, I am getting the return after calling the ajax function whereas I am not getting any return value for the second function. What I am doing wrong
here is my code

<select style="width: 305px;" name="category_id1" id="category_id1" onchange="(function(){ajax('this');return locname('this');})(this)">

my functions are

function ajax(control)
var loc=document.getElementById('category_id1').value;
var req;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
req=new XMLHttpRequest();
{// code for IE6, IE5
req=new ActiveXObject("Microsoft.XMLHTTP");
req.open("POST", "ajax.php?&loc="+loc+"", true);

var items = JSON.parse(result);
var html = '<option value="">Select</option>';
for ( var i = 0; i < items.length; i++ ) {
html += "<option value='" + items[ i ] + "'>" + items[ i ] + "</option>"
document.getElementById("Ultra").innerHTML = html;
function locname(control)
var locName=control.value;
var json = <?php echo $response ?>;
var orgName=document.getElementById("category_id").value;
var html="<option>Select</option>";
var locations;
for(var i=0; i<json.length; i++)
var item = json[i].name;
for(var j=0;j<locations.length;j++){
var location=locations[j].name;
var buildings=locations[j].building
for(var k=0;k<buildings.length;k++)
var building=buildings[k];
html=html+"<option value='"+building+"'>"+building+"</option>";



hsz hsz
Answer Source

Just try with:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download