Reputation: 45
function correlativo(sucursal){
var tipo=document.getElementById('tipo').value;
var correlativo= document.getElementById('correlativo')
var ajax=nuevoAjax();
ajax.open("POST", "../ajax/correlativo_ajax.php", true);
ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
ajax.send("tipo="+tipo+"&sucursal="+sucursal);
ajax.onreadystatechange=function()
{
if (ajax.readyState==4)
{
var respuesta=ajax.responseXML;
correlativo.innerHTML=respuesta.getElementsByTagName("correlativo")[0].childNodes[0].data;
}
}
}
function guardarOt(){
//
var sucursal_ciudad = document.getElementById('sucursal_ciudad').value;
correlativo(sucursal_ciudad); //This line i get the ERROR
}
I have this error :C, i dont know why. Uncaught TypeError: undefined is not a function When I call this function correlativo(); i get this error i dont know why ;( , please helpme i need a lot the solution
Upvotes: 0
Views: 3414
Reputation: 46657
This is most likely happening due to a browser "feature" which creates global variables corresponding to each element on your page, with the element's ID as the variable name.
If you have an element on your page with the ID correlativo
(which you probably do since you're performing getElementById('correlativo')
) this would effectively overwrite your declaration of function correlativo ...
, causing it to not exist when you try to execute it from guardarOt
.
TLDR: Change the name of your correlativo
function to something else and it should work fine.
Upvotes: 1
Reputation: 11718
You must be missing nuevoAjax.
function nuevoAjax(){
var xmlhttp=false;
try {
mlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
xmlhttp = new XMLHttpRequest();
}
return xmlhttp;
};
Upvotes: 0
Reputation: 2150
You have a function and a variable with the name correlativo
. Change one of those.
Also you have nuevoAjax
which is not defined in the code provided. Make sure that this is a function. Not a variable.
Upvotes: 0