0
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

  • What does `nuevoAjax()` return? – David G Jan 24 '13 at 20:25
  • 1
    In which line do you get the error? It seems either `nuevoAjax` or `correlativo` are not available. – Bergi Jan 24 '13 at 20:25
  • 1
    Do you know what the line number is? If so, tell us what code is on that line? – Lee Meador Jan 24 '13 at 20:27
  • i get the error in correlativo(sucursal_ciudad); And function correlativo(sucursal) is in the 1162 line, and function guardarOt() in 1185 – Hector Chacon Perez Jan 24 '13 at 20:29
  • You should not be naming both your variable and function `correlativo`. This is causing a shadow and potentially causing the exception you are seeing. Also, some browsers will create global variables for DOM elements, which would effectively destroy your `correlativo` function. – jbabey Jan 24 '13 at 20:35
  • @jbabey , thanks man :D! you giveme the anwser – Hector Chacon Perez Jan 24 '13 at 20:42
  • @HectorChaconPerez I've posted it as an answer. If it helped solve your problem, you should accept it as the answer. – jbabey Jan 24 '13 at 20:43

3 Answers3

1

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.

Community
  • 1
  • 1
jbabey
  • 45,965
  • 12
  • 71
  • 94
0

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.

Wolf
  • 2,150
  • 1
  • 15
  • 11
0

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;
};
Shanimal
  • 11,517
  • 7
  • 63
  • 76