Connecting Tech Pros Worldwide Help | Site Map

setAttribute on IE solution, but parse problems?

 
LinkBack Thread Tools Search this Thread
  #1  
Old February 11th, 2006, 02:05 AM
Good Man
Guest
 
Posts: n/a
Default setAttribute on IE solution, but parse problems?

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?

  #2  
Old February 11th, 2006, 01:45 PM
shyam
Guest
 
Posts: n/a
Default Re: setAttribute on IE solution, but parse problems?

its as simple as this

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

  #3  
Old February 12th, 2006, 07:45 PM
Good Man
Guest
 
Posts: n/a
Default 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??
  #4  
Old February 13th, 2006, 05:15 PM
shyam
Guest
 
Posts: n/a
Default 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

  #5  
Old February 14th, 2006, 02:35 PM
Good Man
Guest
 
Posts: n/a
Default 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.
  #6  
Old February 14th, 2006, 02:45 PM
Good Man
Guest
 
Posts: n/a
Default 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.
  #7  
Old February 14th, 2006, 05:45 PM
Good Man
Guest
 
Posts: n/a
Default 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.
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.