var button = false;
var B = "<button type='button' script = 'var button = true'>Calculate!</button>" ;
var n = 0;
var y = new Array();
var x = /([1-10])\/10/g ;
var tds = document.getElementsByTagName("td");
var titles = document.getElementsByTagName("h2");
for(var j = 0; j < titles.length; j++) {
var title = titles[j];
title.innerHTML = title.appendChild(B); //Problem is right here.
}
if (button = true){
for(var i = 0; i< tds.length; i++) {
var td= tds[i];
if(td.innerHTML == x)
{
x = y[i];
}
for(var z = 0; z < i; z++)
{
n = n + y[z];
}
window.open(document.write("<p>" + n + "</p>"));
}
}
button = false;
The problem is where the comment specifies it to be. For some reason Greasemonkey won't let me run it.
I don't think that Greasemonkey understands HTMLELement.innerHTML and you need to use the DOM.
“The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
—Tim Berners-Lee, W3C Director and inventor of the World Wide Web
var button = false;
var B = document.createElement("button");
var n = 0;
var y = new Array();
var x = /([1-10])\/10/g ;
var tds = document.getElementsByTagName("td");
var title = document.getElementsByTagName("h2")[0];
B.setAttribute('type', 'button');
B.setAttribute('value', 'var button = true');
B.setAttribute('onclick', 'var button= true')
title.appendChild(B);
if (button = true){
for(var i = 0; i< tds.length; i++) {
var td= tds[i];
if(td.innerHTML == x)
{
x = y[i];
}
for(var z = 0; z < i; z++)
{
n = n + y[z];
}
window.open(document.write("<p>" + n + "</p>")); //Security Error
}
}
button = false;
Error Console is telling me this is a security error. What can be done to fix this?
window.open ('', 'win').document.write ('<p>', n, '<p>');
// or if you're not into the whole brevity thing:
win = window.open ('', 'win');
win.document.write ('<p>', n, '<p>');
Last edited by Charles; 05-22-2009 at 11:45 AM.
“The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
—Tim Berners-Lee, W3C Director and inventor of the World Wide Web
I had a "cut and paste" error up there. Give it another go and if it still isn't working post what you then have.
“The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
—Tim Berners-Lee, W3C Director and inventor of the World Wide Web
I got to leave for work soon so I'll just post what I have so far.
Code:
var button = false;
var B = document.createElement("button");
var n = 0;
var y = new Array();
var x = /([1-10])\/10/g ;
var tds = document.getElementsByTagName("td");
var title = document.getElementsByTagName("h2")[0];
B.setAttribute('type', 'button');
B.setAttribute('value', 'Calculate!');
B.setAttribute('onclick', 'button= true');
//t = B.firstChild.document.createElement("p");
//t.nodeValue = "Calculate!"
title.appendChild(B);
if (button = true){
for(var i = 0; i< tds.length; i++) {
var td= tds[i];
if(td.innerHTML == x)
{
parseFloat('x');
x = y[i];
}
for(var z = 0; z < i; z++)
{
n = n + y[z];
}
}
window.open('', 'win', height = 300, width = 300).document.write('<p>' + (n/z) + '</p>'); //Security Error.
}
button = false;
“The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
—Tim Berners-Lee, W3C Director and inventor of the World Wide Web
Well, whatever. Everything else works, syntax wise. However I still have one nagging problem. I wanted this program to cycle through <td> elements and scoop up everything in a "n/10" format and calculate the average mean. For some reason it's not displaying the result. I'll post what I have so far.
Code:
var button = false;
var B = document.createElement("input");
var n = 0;
var y = new Array();
var x = /([0-9]{2})\/10/g ;
var c = 0;
var tds = document.getElementsByTagName("td");
var title = document.getElementsByTagName("h2")[0];
B.setAttribute('type', 'button');
B.setAttribute('value', 'Calculate!');
B.setAttribute('onclick', 'button= true');
title.appendChild(B);
if (button = true){
for(var i = 0; i< tds.length; i++) {
var td= tds[i];
if(td.innerHTML == x)
{
parseFloat('x');
if(x.NaN = true){
i++;
c++;
}
if(x < 1){
i++;
c++;
}
if(x > 10){
i++;
c++;
}
x = y[i];
n = n + y[i];
}
//for(var z = 0; z < i; z++)
//{
//n = n + y[z];
//}
}
window.open('', 'win', 'height=300,width=300').document.write('<p>', (n/(i-c)), '</p>');
}
button = false;
Bookmarks