Connecting Tech Pros Worldwide Help | Site Map

setAttribute on IE solution, but parse problems?

Good Man
Guest
 
Posts: n/a
#1: Feb 11 '06
Hi there

I'm cloning DOM elements on the fly, and I need to assign different
"onchange" attributes. As many others have discovered and documented, the
following works with Mozilla but not IE:

var mystring = "describeQuote(this,'"+newCount+"')";
quoteDesc.setAttribute("onchange",mystring);

I've found the generally agreed-upon solution to setting an attribute
cross-browser:

var mystring = function() {
"describeQuote(this,'"+newCount+"');"
}
quoteDesc.onchange = mystring;


My problem is, I need to parse the variable 'newCount'. It gets parsed in
the first (non-IE) example (as '3' or '5' etc...). When I look at the
onchange value after using the second example, it is quite literally
"describeQuote(this,'"+newCount+"');" - quotes, plus-signs, and the word
newCount instead of a number.

How can I get newCount parsed in the second example?
shyam
Guest
 
Posts: n/a
#2: Feb 11 '06

re: setAttribute on IE solution, but parse problems?


its as simple as this

quoteDesc.onchange = function(newCount) {
describeQuote(this, newCount);
}

Good Man
Guest
 
Posts: n/a
#3: Feb 12 '06

re: setAttribute on IE solution, but parse problems?


"shyam" <xshyamx@gmail.com> wrote in news:1139668249.978845.322040
@g44g2000cwa.googlegroups.com:
[color=blue]
> its as simple as this
>
> quoteDesc.onchange = function(newCount) {
> describeQuote(this, newCount);
> }
>
>[/color]

hi, that does not appear to work. newCount remain unparsed, and is the
WORD newCount instead of the numeric variable.

help??
shyam
Guest
 
Posts: n/a
#4: Feb 13 '06

re: setAttribute on IE solution, but parse problems?


sorry posted in a hurry...:(

quoteDesc.onchange = function(newCount) {
describeQuote(this, newCount);
}
does not work because each time the onchange handler is expecting an
agrument and not getting it.
quoteDesc.onchange = function() {
describeQuote(this, newCount);
}
doesn't work either....what we need is another closure sorta like this
[...]
quoteDesc.onchange = getChangeHandler(quoteDesc, newCount);
[...]
function getChangeHandler(target, count) {
return function() {
describeQuote(target, count);
};
}
not too elegant i guess but gets the job done

Good Man
Guest
 
Posts: n/a
#5: Feb 14 '06

re: setAttribute on IE solution, but parse problems?


"shyam" <xshyamx@gmail.com> wrote in news:1139853629.097912.267500
@g47g2000cwa.googlegroups.com:
[color=blue]
> sorry posted in a hurry...:(
>
> quoteDesc.onchange = function(newCount) {
> describeQuote(this, newCount);
> }
> does not work because each time the onchange handler is expecting an
> agrument and not getting it.
> quoteDesc.onchange = function() {
> describeQuote(this, newCount);
> }
> doesn't work either....what we need is another closure sorta like this
> [...]
> quoteDesc.onchange = getChangeHandler(quoteDesc, newCount);
> [...]
> function getChangeHandler(target, count) {
> return function() {
> describeQuote(target, count);
> };
> }
> not too elegant i guess but gets the job done[/color]

hi

i guess i am mental or something, but in this case again, 'count' is not
parsed, and the onchange remains quite literally

"function() {
describeQuote(target,count);
}"


i think im going to give up and use dirty innerHTML to rewrite the code
that way. thanks.
Good Man
Guest
 
Posts: n/a
#6: Feb 14 '06

re: setAttribute on IE solution, but parse problems?


Good Man <heyho@letsgo.com> wrote in news:Xns976A6A86473D3sonicyouth@
216.196.97.131:

[color=blue]
> i guess i am mental or something, but in this case again, 'count' is not
> parsed, and the onchange remains quite literally[/color]

i am beginning to think that my inclusion of the infamous "prototype.js"
library is screwing up what should be, by all accounts, a simple fix.

arrrgh.
Good Man
Guest
 
Posts: n/a
#7: Feb 14 '06

re: setAttribute on IE solution, but parse problems?


Good Man <heyho@letsgo.com> wrote in news:Xns976A6A86473D3sonicyouth@
216.196.97.131:
[color=blue]
> i guess i am mental or something, but in this case again, 'count' is not
> parsed, and the onchange remains quite literally
>
> "function() {
> describeQuote(target,count);
> }"[/color]

nothing a little eval() didn't fix. blah blah, don't use eval - where here
is what i did:


mystring = describeQuote(target,count);

function getChangeHandler(target, count) {
return function() {
eval(mystring);
};
}


i simply HAD to use eval to parse the 'target' and 'count' js variables,
otherwise they remained as literal terms in the end.

thanks for your help. i wrestled with this for far, far too long.
Closed Thread


Similar JavaScript / Ajax / DHTML bytes