Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Whats going on here? JS hates me... Type Mismatch error 2

Status
Not open for further replies.

snowboardr

Programmer
Joined
Feb 22, 2002
Messages
1,401
Location
PH
I sware javascript hates me and no one else! I have looked at this code for the last 2 hours and just can't seem to get it to work :( I wouldn't see why I can't pass an id to the other function on this line:

Ps. I am getting a type mismatch error, I have tried joining these two functions together, but nothing happens...


Code:
    LoadPOSTHTMLHttp.onreadystatechange = getLoadPOSTHTMLHttpResponse(intRow);

Code:
var LoadPOSTHTMLHttp = null;
function LoadPOSTHtml(iCall,cat1,cat2,intRow) {
    LoadPOSTHTMLHttp = createRequestObject();
    var url2="ajax_display.asp?call=" + iCall + "&cat1=" + cat1 + "&cat2=" + cat2
    LoadPOSTHTMLHttp.open('GET', url2, true);
    LoadPOSTHTMLHttp.onreadystatechange = getLoadPOSTHTMLHttpResponse(intRow);
    LoadPOSTHTMLHttp.send('');
	
}

function getLoadPOSTHTMLHttpResponse(intRowRow) {
	alert('true')
    if (LoadPOSTHTMLHttp != null)
        if (LoadPOSTHTMLHttp.readyState == 4)
            if (LoadPOSTHTMLHttp.status == 200)
                document.getElementById('viewpoststable'+intRowRow).innerHTML = LoadPOSTHTMLHttp.responseText;
}



function createRequestObject() {
    var ro;
    /*@cc_on
    @if (@_jscript_version >= 5)
        try {
            ro = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                ro = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (E) {
                ro = false;
            }
        }
    @else
        ro = false;
    @end @*/
    if (!ro && typeof XMLHttpRequest != 'undefined') {
        try {
            ro = new XMLHttpRequest();
        } catch (e) {
            ro = false;
        }
    }
    return ro;
}
 
just a shot in the dark, does this work?

Code:
LoadPOSTHTMLHttp.onreadystatechange = function(intRow) { getLoadPOSTHTMLHttpResponse(intRow); }



*cLFlaVA
----------------------------
[tt]( <P> <B>)13 * (<P> <.</B>)[/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
You can't pass a variable in the onstatechange like that. Make the variable a global and access it from within the getLoadPOSTHTMLHttpResponse() function.
Code:
var intRow = null;
var LoadPOSTHTMLHttp = null;
function LoadPOSTHtml(iCall,cat1,cat2,_intRow) {
    intRow = _intRow;
    LoadPOSTHTMLHttp = createRequestObject();
    var url2="ajax_display.asp?call=" + iCall + "&cat1=" + cat1 + "&cat2=" + cat2
    LoadPOSTHTMLHttp.open('GET', url2, true);
    LoadPOSTHTMLHttp.onreadystatechange = getLoadPOSTHTMLHttpResponse();
    LoadPOSTHTMLHttp.send('');   
}

function getLoadPOSTHTMLHttpResponse() {
    alert('true')
    if (LoadPOSTHTMLHttp != null)
        if (LoadPOSTHTMLHttp.readyState == 4)
            if (LoadPOSTHTMLHttp.status == 200)
                document.getElementById('viewpoststable'+intRow).innerHTML = LoadPOSTHTMLHttp.responseText;
}
Cheers,
Jeff

[tt]Jeff's Page @ Code Couch
[/tt]

What is Javascript? FAQ216-6094
 
No its passing undefined where this alert is below, however when I tried putting the value in for intRowRow (static number) in this part
Code:
document.getElementById('viewpoststable'+intRowRow).innerHTML = LoadPOSTHTMLHttp.responseText;
}


function getLoadPOSTHTMLHttpResponse(intRowRow) {
if (LoadPOSTHTMLHttp != null)
if (LoadPOSTHTMLHttp.readyState == 4)
if (LoadPOSTHTMLHttp.status == 200)
alert('viewpoststable'+intRowRow)
document.getElementById('viewpoststable'+intRowRow).innerHTML = LoadPOSTHTMLHttp.responseText;
}
 
Thanks Jeff for pointing that out.. I am getting a type mismatch error somewhere in that code any ideas what that could be?
 
Using Jeff's previous code try removing the brackets from the end of this line:

Code:
LoadPOSTHTMLHttp.onreadystatechange = getLoadPOSTHTMLHttpResponse[!]()[/!];

Hope this helps,
Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Yes... I'm picking that it's erroring when you are trying to use document.getElementById() and it's evaluating the intRowRow variable to be undefined... effectively you end up with:
Code:
document.getElementById('viewpoststable[b]undefined[/b]').innerHTML = LoadPOSTHTMLHttp.responseText;
That's what I imagine is happening, anyway.

By taking my suggestion of making it a global variable, you avoid that problem altogether.

Cheers,
Jeff

[tt]Jeff's Page @ Code Couch
[/tt]

What is Javascript? FAQ216-6094
 
Thanks a bunch both of you! You were right about the () BillyRay ... javascript is really picky [evil][thumbsdown]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top