/    Sign up×
Community /Pin to ProfileBookmark

js newb, adding dom element works in ie 6, ff2 but not ns7.02?

Hello all, I’m rather a new to javascript (more of a backend guy usually). I’m trying to dynamically add some dom elements and I’m using a combination of prototype.js and Behaviour.js. Here’s the code I have regarding adding the dom elements:

[code]
function initialize(){
removeChildNodes($(‘customSearchPopup’));

for(var i=0; i<array.length; i++){
var splitLabel = array[i].split(“.”);
var actualLabel = splitLabel[splitLabel.length -1];
var a = document.createElement(“a”);

a.setAttribute(“href”,”#”);
a.innerHTML = actualLabel;
a.customSearch = data[array[i]];
$(‘customSearchPopup’).appendChild(a);

Event.observe(a, ‘click’, function(event){
var ahref = Event.element(event);
var terms = $A($(‘advancedSearchForm’).searchForm.getTerms());
terms.each(function(term){
term.searchTerm.removeThisTerm();
});
$(‘advancedSearchForm’).searchForm.deserialize(ahref.customsearch);
});
}
}
}

Behaviour.addLoadEvent(function(){
initialize();
});
[/code]

the above code works just in both ie6 and ff2 but gives me nothing at all in ns7.02 (although in ie 6, a refresh of the page causes the same thing that happens in ns when the page is initially hit). I don’t believe this is an issue of compatibility between prototype/behavior and ns7 (at least I can’t find a reference to that anywhere) so I imagine it’s an issue of my incomplete grasp of javascript. Does anyone have any advice?

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@cmoauthorJul 16.2007 — ok, well it looks like the problem I'm having is this:
<i>
</i>var a = document.createElement("a");
...
a.customsearch = data[array[i]];
...
Event.observe(a, 'click', function(event){
var ahref = Event.element(event);
....
do something with ahref.customsearch;
});


both ie 6 and ff2 are just fine with defining a new property on the a variable. However, it appears that netscape 7 is not fine with that and is getting ahref.customsearch as undefined. Sadly I don't know quite enough javascript/dom manipulation to understand exactly what is amiss here - could anyone point me in the right direction? Thanks!
×

Success!

Help @cmo spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...