473,379 Members | 1,170 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

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?
Feb 11 '06 #1
6 1928
its as simple as this

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

Feb 11 '06 #2
"shyam" <xs*****@gmail.com> wrote in news:1139668249.978845.322040
@g44g2000cwa.googlegroups.com:
its as simple as this

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


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

help??
Feb 12 '06 #3
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

Feb 13 '06 #4
"shyam" <xs*****@gmail.com> wrote in news:1139853629.097912.267500
@g47g2000cwa.googlegroups.com:
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


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.
Feb 14 '06 #5
Good Man <he***@letsgo.com> wrote in news:Xns976A6A86473D3sonicyouth@
216.196.97.131:

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


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.
Feb 14 '06 #6
Good Man <he***@letsgo.com> wrote in news:Xns976A6A86473D3sonicyouth@
216.196.97.131:
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);
}"


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.
Feb 14 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: timmy_dale12 | last post by:
Hello , im a java programmer whos gotten tangled up in some javascripts. Im really stuck on this one can , can aybody explain this to me. I have a javscript which is to clone a table row and...
6
by: Tim Johnson | last post by:
Hello All: Using javascript to dynamically add row elements to a table. as in ..... row.setAttribute("bgcolor",rowColor); // or cell.setAttribute("bgcolor",rowColor); Using firefox or...
21
by: James Black | last post by:
I am curious if there is a benefit to set attributes directly, in my javascript, or to use setAttribute. For example, I have this: var input = document.createElementNS(xhtmlNS, 'input');...
11
by: jesdynf | last post by:
I'm having trouble applying a stylesheet to content I'm generating after the fact. Here's the sample code: <html> <head> <title>CSS/DOM Problem Example</title> <style type="text/css">...
2
by: Aaron Gray | last post by:
Whats going on with setAttribute on IE it appears to work on some examples and working code but not on other code that I am writting ? <style> .foo { font-size: 200%; } </style>
4
by: ICPooreMan | last post by:
I've got some code which works in firefox that's giving me fits in IE7 (maybe other versions too I haven't tested it). What I want to do is get the oncontextmenu attribute of something, change the...
2
by: chris10121 | last post by:
for(var i = 0; i < 12; i++) { dv = document.createElement('div'); dv.setAttribute("id",i.toString()); dv.className="time"; if(i == 0) {...
2
by: maminx | last post by:
hello all, i have this script below var td = document.createElement('td'); var theInput = document.createElement('input'); theInput.setAttribute('type', 'text');...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.