Welcome to WebmasterWorld Guest from 23.22.220.37

Forum Moderators: open

Message Too Old, No Replies

What's the equivalent of 'setAttribute' for IE6?

I think I have it but need help with the command format.

     
7:12 am on Oct 17, 2007 (gmt 0)

Junior Member

5+ Year Member

joined:Apr 20, 2006
posts: 56
votes: 0


Hi,

The following works perfectly in ff:


elem.setAttribute("onBlur","updateField('t_',this.value,'"+recordId+"','"+escape(data_nohead)+"')");

But I need to accomodate IE6 & 7. The following works in IE7 but in IE6 is doesn't include the 4th parameter 'escape(data_nohead)':


elem.onBlur = function elem(){ updateField('t_',this.value,recordId,escape(data_nohead));};

'data_nohead', is a string variable.

Can someone help me please?

Thanks

7:30 am on Oct 17, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Nov 3, 2005
posts:1585
votes: 0


'data_nohead' needs to be a global variable (as does recordId)

elem.onBlur = function elem(){ updateField('t_',this.value,recordId,escape(data_nohead));};

function does not need to be named, leave red bit out, naming it the same as variable elem not a great idea?

8:01 am on Oct 17, 2007 (gmt 0)

Junior Member

5+ Year Member

joined:Apr 20, 2006
posts: 56
votes: 0


Thanks Dave. I've corrected the function declaration by removing the name as you suggested. It now looks like this:


elem.onBlur = function(){ updateField('t_',this.value,recordId,escape(data_nohead));};

Regarding the two variables, 'data_nohead' and 'recordId', I just got them alerted back to me immediately before where I used them above, and they were both present.

I'm trying to understand why they need to be globals? Once data_nohead has deposited it's contents as a string in the parameters list, I should have no further need for the variable.

What I'm wondering is whether I need to put that parameter (the last one), in quotes and if so, what type?

10:07 am on Oct 17, 2007 (gmt 0)

Junior Member

5+ Year Member

joined:Apr 20, 2006
posts: 56
votes: 0


I finally found the problem. I discovered that the event handlers are case sensitive and that they have to be in lower case to work in Internet Explorer!

Thanks for highlighting the problem with my naming of functions. :)

Regards, peter

11:45 am on Oct 17, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Nov 3, 2005
posts:1585
votes: 0


For the record. When the onblur occurs this is executed

updateField('t_',this.value,recordId,escape(data_nohead));

the variables need to exist at this time. This differs from the setAtribute case where the value of recordId is encoded into the function.

2:03 pm on Oct 17, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:Mar 29, 2007
posts:1147
votes: 0


Better to use addevent for event handlers, as this will prevent overwriting any other events.