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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem with IE

Status
Not open for further replies.

richardko

Programmer
Jun 20, 2006
127
US
hi,
I need add an attribute function to a text box i create. I use the script below and it seems to work fine with Firefox but it doesnt work with IE. Any idea?

if (window.attachEvent) {
textElem.attachEvent("onblur", function(){
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url=" url=url+"?sku="+document.getElementById(name).value
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
});
} else if (window.addEventListener) {
textElem.setAttribute("onblur","ajaxrequest('"+name+"','"+lineId+"','"+id+"')");
}
 
Not sure if this is the issue or not... but maybe worth looking into...

You're testing for "window.addEventListener" and then using "setAttribute". Try changing this:

Code:
textElem.setAttribute("onblur", "ajaxrequest('" + name + "','" + lineId + "','" + id + "')");

to this:

Code:
textElem.addEventListener("blur", "ajaxrequest('" + name + "','" + lineId + "','" + id + "')", false);

Hope this helps,
Dan

Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
hi,
Thanks for the reply. However, i get
"Error: uncaught exception: null" error when i use the code above.
any idea?
 
This is the full script for what i am trying but it now fails both in firefox and IE.

var textElem = document.createElement("input");
textElem.setAttribute("type", "text");
textElem.setAttribute("name", name);
textElem.setAttribute("id", name);

if (textElem.addEventListener){
textElem.addEventListener('click', sendrequest, false);
} else if (textElem.attachEvent){
textElem.attachEvent('onclick', sendrequest);
}
 
never mind the post above...the code above works. But i dont understand why does the code execute when the button is created rather than when the event takes place.
Here is the modified code:
if (textElem.addEventListener){
textElem.addEventListener('click', sendrequest(name,lineId,id), false);
} else if (textElem.attachEvent){
textElem.attachEvent('onclick', sendrequest(name,lineId,id));
}

the funcion being called is:

function sendrequest(name,lineId,id){
alert("innnn");
var req = new Ajax.Request(' {
method: 'get',
parameters:'sku='+document.getElementById(lineId+exsku+id).value+'&lineId='+lineId+'&id='+id,
onComplete:processJSON
});
}
 
Because you're calling the function and passing the return parameter of it through to the addEvent call... To not call the function, give only the function name (without the brackets and args).

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
hi Dan,
I create multiple text boxes which need to call the function and each of them has to have different parameters.
How would I add parameters to the function when using "addEventListener" or "attachEvent" then?

thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top