Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Uziel
Jun 28, 2004

Ask me about losing 200lbs, and becoming the Viking God of W&W.

Wheany posted:

Try putting a breakpoint on the first row of closeIt (var count = 0).

Does the breakpoint ever trigger?

What is the value of tpMods when paused on the above breakpoint?
I put the breakpoint on the first row like you said, it never triggers (Visual Studio 2010).
However, whenever I try to close the window, I always get the prompt. Using Chrome's javascript console, count is undefined.

The treepanel is created in markup with a hidden root node. On the initial page load, it will always be empty except for the root. When a user makes changes, those changes are added to the tree panel.

I put the closeIt method in the body's onload event, and then I do get that tpMods is undefined.

Edit: I figured it out. Was a combination of a function

code:
  <script type="text/javascript">
        WarnOnClose = function (yes) {
            if (yes) {
                window.onbeforeunload = function () {
                    return "You currently have unsaved pending mods.";
                };
            }
            else {
                window.onbeforeunload = null;
            }
        };
    </script>
And codebehind using ext's X.Call:
code:
  if (SessionCal.PendingMods.Count > 0)
                X.Call("WarnOnClose", true);
            else
                X.Call("WarnOnClose", false);

Uziel fucked around with this message at 13:00 on Oct 10, 2012

Adbot
ADBOT LOVES YOU

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
What is codebehind?

Uziel
Jun 28, 2004

Ask me about losing 200lbs, and becoming the Viking God of W&W.

Suspicious Dish posted:

What is codebehind?
Sorry for not being specific. This is an asp.net page, so this code appears in in the codebehind file.

angry_keebler
Jul 16, 2006

In His presence the mountains quake and the hills melt away; the earth trembles and its people are destroyed. Who can stand before His fierce anger?
I'm writing an xfa script to hide all of the 8 fields with the same name on page 1 in a pdf. The code I want to use is:

code:
for(var count=0; count<7; count++){

     xfa.form.formname.page1.resolveNode("field_name[count]").presence = "invisible";
}
I know that's a bad SOM expression, but I can't for the life of me figure out the right way to iterate through subnodes.

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope
Just a guess, because I don't know anything about xfa script, but maybe
JavaScript code:
xfa.form.formname.page1.resolveNode("field_name[" + count + "]").presence = "invisible";

angry_keebler
Jul 16, 2006

In His presence the mountains quake and the hills melt away; the earth trembles and its people are destroyed. Who can stand before His fierce anger?
Yep that did the trick. Shine on you crazy diamond :swoon:

My Rhythmic Crotch
Jan 13, 2011

Does anyone know of something like Kendo UI (in terms of simplicity) that is a little more mature? I like how easy it is to develop with, but I'm finding too many bugs and lack of support for pretty important stuff (like nested JSON in your datasource). There's got to be something that's more mature yet just as easy to develop with. Any ideas?

Uziel
Jun 28, 2004

Ask me about losing 200lbs, and becoming the Viking God of W&W.

My Rhythmic Crotch posted:

Does anyone know of something like Kendo UI (in terms of simplicity) that is a little more mature? I like how easy it is to develop with, but I'm finding too many bugs and lack of support for pretty important stuff (like nested JSON in your datasource). There's got to be something that's more mature yet just as easy to develop with. Any ideas?
http://www.sencha.com/products/extjs
and/or
http://ext.net/

I use ext.net and their support is really good even for the community license

My Rhythmic Crotch
Jan 13, 2011

Uziel posted:

http://www.sencha.com/products/extjs
and/or
http://ext.net/

I use ext.net and their support is really good even for the community license
I've actually been evaluating Ext JS at the same time as Kendo. It does seem very mature, but I'm basically a one-man-band developing the entire site, and the learning curve for Ext JS is really putting me off. Perhaps I will just have to stick with it.

Spatulater bro!
Aug 19, 2003

Punch! Punch! Punch!

I'm trying to use the appendChild method and loops to automatically create a table with 1000 rows and 1000 columns. My code only creates a single row with 1000 columns. What am I doing wrong?

code:
var table = document.createElement("table");
table.setAttribute("cellspacing", "0");
table.setAttribute("width", "100%");
table.setAttribute("height", "auto");
table.setAttribute("border", "1");
        
for (i = 0; i < 1001; i++) {
	var tr = document.createElement("tr");
            
        for (i = 0; i < 1001; i++) {
        	var td = document.createElement("td");
                        
                tr.appendChild(td);
        }
        
        table.appendChild(tr);
}
        
document.body.appendChild(table);

Peanut and the Gang
Aug 24, 2009

by exmarx
You're using the 'i' variable for both loops! Oh no!!! Name the inner loop's variable 'j' or something else.

(Also, you've got an off by one; that builds 1001 of them.)

Spatulater bro!
Aug 19, 2003

Punch! Punch! Punch!

Ahhhh, forgot about the rules of scope. Thanks!

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope
Also, it looks like you make a local variable "table" at the start of your code, then use a global variable "i".

Assuming you only changed your inner loop to use j instead of i, you also use a global variable there.

Spatulater bro!
Aug 19, 2003

Punch! Punch! Punch!

Wheany posted:

Also, it looks like you make a local variable "table" at the start of your code, then use a global variable "i".

Assuming you only changed your inner loop to use j instead of i, you also use a global variable there.

Sorry, I'm not following. As I understand it, "table" is global and "i" and "j" are both local (since they only exist inside the loops). Is this not correct? What are you saying needs to be changed?

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
JavaScript doesn't have block scope. It has function scope. So there's "globals", which are visible to the entire program, and "locals", which are visible to the current function.

Forgetting to declare a variable with "var" before using it means you've made a global instead of a local.

Spatulater bro!
Aug 19, 2003

Punch! Punch! Punch!

Ah, I forgot var in front of i. Okay. So if I had put var in front of both "i"s in the first place, would I still need to change the inner i to j?

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
JavaScript code:
for (var i = 0; i < 10; i++) {
    for (var i = 0; i < 10; i++) {
        print(i);
    }
}
is equivalent to:

JavaScript code:
var i;
var i;
for (i = 0; i < 10; i++) {
    for (i = 0; i < 10; i++) {
        print(i);
    }
}

Golbez
Oct 9, 2002

1 2 3!
If you want to take a shot at me get in line, line
1 2 3!
Baby, I've had all my shots and I'm fine
I would think so, because...

code:
for (i = 0; i < 100; i++)
{
    for (j = 0; j < 100; j++)
    {
        echo i+j;
    }
}
If the above is valid code, then you can't expect to reuse i for the second look and expect anything to work. Can you really have two 'i's coexist just because of a for loop? This is not something I've run in to because I don't reuse 'i' just for the hell of it. :v:

Edit: Also that. One weirdness about JS I learned from Crockford is that it internally moves variable declarations to the top, leading to weirdness if you were operating on the assumption that they were being declared in place.

Golbez fucked around with this message at 15:35 on Oct 17, 2012

Spatulater bro!
Aug 19, 2003

Punch! Punch! Punch!

Excellent, both of those answers help clear it up.

The problem I'm having is that I'm learning both JS and PHP at the same time, as well as doing some basic VB.NET at work. A hazy understanding of three different languages leads to some serious mix ups.

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

Golbez posted:

code:
for (i = 0; i < 100; i++)
{
    for (j = 0; j < 100; j++)
    {
        echo i+j;
    }
}
If the above is valid code, then you can't expect to reuse i for the second look and expect anything to work. Can you really have two 'i's coexist just because of a for loop? This is not something I've run in to because I don't reuse 'i' just for the hell of it. :v:

Edit: Also that. One weirdness about JS I learned from Crockford is that it internally moves variable declarations to the top, leading to weirdness if you were operating on the assumption that they were being declared in place.

When you use a var declaration, the variables you declare have function scope. So this:
JavaScript code:
function someFunction() {
	console.log('butts');
	for (var i = 0; i < 100; i++)
	{
	    for (var j = 0; j < 100; j++)
	    {
	        echo i+j;
	    }
	}
}
becomes this
JavaScript code:
function someFunction() {
	var i;
	var j;
	console.log('butts');
	for (i = 0; i < 100; i++)
	{
	    for (j = 0; j < 100; j++)
	    {
	        echo i+j;
	    }
	}
}
if you dont't use a var declaration (and the code runs in a web browser):
JavaScript code:
function someFunction() {
	for (i = 0; i < 100; i++)
	{
	    for (j = 0; j < 100; j++)
	    {
	        echo i+j;
	    }
	}
}
becomes:
JavaScript code:
function someFunction() {
	for (window.i = 0; window.i < 100; window.i++)
	{
	    for (window.j = 0; window.j < 100; window.j++)
	    {
	        echo window.i+window.j;
	    }
	}
}
To use two i's, you'd have to do this:
JavaScript code:
function someFunction() {
	var i; // outer i
	for (var i = 0; i < 3; i++)
	{
		(function () {
			var i; // shadows outer i
			for (var i = 0; i < 4; i++)
			{
				console.log("you cannot access the outer i here:" + i);
			}
		}());
	}
}
That outputs:
code:
you cannot access the outer i here:0
you cannot access the outer i here:1
you cannot access the outer i here:2
you cannot access the outer i here:3
you cannot access the outer i here:0
you cannot access the outer i here:1
you cannot access the outer i here:2
you cannot access the outer i here:3
you cannot access the outer i here:0
you cannot access the outer i here:1
you cannot access the outer i here:2
you cannot access the outer i here:3

Atom
Apr 6, 2005

by Y Kant Ozma Post

caiman posted:

Excellent, both of those answers help clear it up.

The problem I'm having is that I'm learning both JS and PHP at the same time, as well as doing some basic VB.NET at work. A hazy understanding of three different languages leads to some serious mix ups.

The trick is that Javascript's var keyword does the exact opposite of PHP's global keyword, since PHP assumes local, and Javascript assumes global. (PHP's design is probably superior in this aspect, I can't count how many times I've polluted global in JS.)

MrHyde
Dec 17, 2002

Hello, Ladies
I ran into this interesting problem at work. A coworker told me you couldn't edit the <head> tag after a page had loaded. I didn't believe him so I set up the following test:
code:
<html>
<head>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>  
</head>
<body>
    <script type="text/javascript">
    $().ready(function() { 
        var testScript = document.createElement("script");
        testScript.src = "test.js";
        testScript.type = "text/javascript";
        $('head').append(testScript);

        var styles = document.createElement('link');
        styles.type = 'text/css';
        styles.rel = 'stylesheet';
        styles.href = 'test.css';
        $('head').append(styles);

        //I expect both of these to be in the head since I just added them
        //but for some reason only the style ends up being there
        var testScriptInHead = $('script[src$="test.js"]').length > 0 ? "Script in head!" : "Script NOT in head";
        var testStyleInHead = $('link[href$="test.css"]').length > 0 ? "Style in head!" : "Style NOT in head";
        alert(testScriptInHead);
        alert(testStyleInHead);
    });
    </script>
    <div class="textcontainer">
    </div>
</body>
</html>
This resulted in the weirdest behavior. The script code runs and the styles are applied, but you'll notice I put in some extra checking in there to try and get my script/style back out. For some reason I can only find the style in the head after I've added the two.

If both were available I could just assume my coworker is wrong (this works in all 3 browsers as far as I can tell) and if neither showed up I'd assume he was right. Since only one of the items shows up I have no idea what's going on now. Anyone have any ideas why this behavior happens?

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

Atom posted:

The trick is that Javascript's var keyword does the exact opposite of PHP's global keyword, since PHP assumes local, and Javascript assumes global. (PHP's design is probably superior in this aspect, I can't count how many times I've polluted global in JS.)

Which is why you always use strict mode and jslint or jshint.

And more functions.

MrHyde posted:

I ran into this interesting problem at work. <snip> Anyone have any ideas why this behavior happens?

My guess is that for security reasons you might not be able to access script tags maybe?

But you definitely can edit the head tag. That exactly how for example LESS works.

Also, please use console.log instead of alert if you must dump the state of some variable.

Gazpacho
Jun 18, 2004

by Fluffdaddy
Slippery Tilde
jQuery does not really insert script elements for IE compatibility reasons. It evaluates the code instead.

Relevant source code:
https://github.com/jquery/jquery/blob/2defcf96e571728b0a565527a532feb30466ebf4/src/manipulation.js#L333
https://github.com/jquery/jquery/blob/2defcf96e571728b0a565527a532feb30466ebf4/src/manipulation.js#L629
https://github.com/jquery/jquery/blob/2defcf96e571728b0a565527a532feb30466ebf4/src/manipulation.js#L689

Gazpacho fucked around with this message at 08:30 on Oct 19, 2012

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
That would make sense if he actually inserted the script tag with jQuery. He doesn't.

EDIT: oh, nevermind. He does insert the script tag with jQuery, yeah.

Try document.head.appendChild instead.

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

Golbez posted:

I would think so, because...

code:
for (i = 0; i < 100; i++)
{
    for (j = 0; j < 100; j++)
    {
        echo i+j;
    }
}
If the above is valid code, then you can't expect to reuse i for the second look and expect anything to work. Can you really have two 'i's coexist just because of a for loop? This is not something I've run in to because I don't reuse 'i' just for the hell of it. :v:

Edit: Also that. One weirdness about JS I learned from Crockford is that it internally moves variable declarations to the top, leading to weirdness if you were operating on the assumption that they were being declared in place.

Random question, but did you by any chance attend the Web Directions conference in Sydney last week?

az jan jananam
Sep 6, 2011
HI, I'M HARDCORE SAX HERE TO DROP A NICE JUICY TURD OF A POST FROM UP ON HIGH
I'm trying to write a Greasemonkey script that will convert Arabic/Farsi text from Arial to Tahoma. Is there a simple way to detect if body text is in Arabic or Farsi?

Golbez
Oct 9, 2002

1 2 3!
If you want to take a shot at me get in line, line
1 2 3!
Baby, I've had all my shots and I'm fine

Gnack posted:

Random question, but did you by any chance attend the Web Directions conference in Sydney last week?

I wish I'd been in Sydney, no.

Gazpacho
Jun 18, 2004

by Fluffdaddy
Slippery Tilde
e: I need to learn not to reply to things I don't know anything about.

Gazpacho fucked around with this message at 02:07 on Oct 23, 2012

some kinda jackal
Feb 25, 2003

 
 
Any recommendations for a good OSX IDE for Node? I don't expect there is a lot out there. Syntax highlighting would be nice, code folding would be nice, autocompletion would be stellar but I'm not expecting much.

dizzywhip
Dec 23, 2005

Zombietoof posted:

Any recommendations for a good OSX IDE for Node? I don't expect there is a lot out there. Syntax highlighting would be nice, code folding would be nice, autocompletion would be stellar but I'm not expecting much.

Sublime Text!

smug forum asshole
Jan 15, 2005
MacVim with a JSHint plugin?

Peanut and the Gang
Aug 24, 2009

by exmarx

Zombietoof posted:

Any recommendations for a good OSX IDE for Node? I don't expect there is a lot out there. Syntax highlighting would be nice, code folding would be nice, autocompletion would be stellar but I'm not expecting much.

WebStorm. Its made by the jetbrains guys and its built specifically for js/node

some kinda jackal
Feb 25, 2003

 
 
Going to give WebStorm a try, thanks! I can definitely get the $29 student license if I like it.

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope
Can I actually stop the loading of page elements with javascript? I have made a user script for the PYF gif thread that convert img tags in read messages to links. That works, but the original purpose was to not even load all the gifs in the read posts.

Well, looking at the network tab in the debugger shows that the images are still being downloadad :mad:

This userscript is made for Opera, but can be easily made to work with Greasemonkey and Chrome as well.

The original code is in the readReplacer function, but that runs only after the DOM content has loaded. So my second idea was listening to DOMNodeInserted and intercepting the body tag and then the image tags inside it.

Except Opera does not fire a DOMNodeInserted for body or any tags inside it (in the first pass?). document.body just appears suddenly. That's why I'm testing for document.body in loadingReplacer.

So my next idea was using Opera's user script specific functions, and to listen to BeforeEvent, which fires before any actual events.

Except document.body suddenly simply materializes there as well.

So I tried one more thing. First I replace all the read images with links, then stop page loading (window.stop()), then I reset the remaining image srcs. The theory was that it would resume loading the images.

Except it never even stops loading them.

So here is the resulting trainwreck of code:
JavaScript code:
// ==UserScript==
// @name read gifs to links
// @description Make gifs in read messages into links on some of Something Awful's image heavy threads
// @include http://forums.somethingawful.com/showthread.php*threadid=3457178*
// ==/UserScript==
/*jslint browser: true, plusplus: true, continue: true, devel: true */

(function () {
	"use strict";
	var beforeReplacer,
		loadingReplacer,
		readReplacer,
		readReplacerRun = false;

	beforeReplacer = function (userJSEvent) {
		//console.log('beforeReplacer');
		if (userJSEvent.srcElement.nodeName && userJSEvent.srcElement.nodeName === 'BODY') {
			//console.warn('srcElement = body');
		}
		if (userJSEvent.target.nodeName && userJSEvent.target.nodeName === 'BODY') {
			//console.warn('target = body');
		}
		if (userJSEvent.event.relatedNode && userJSEvent.event.relatedNode.nodeName === 'BODY') {
			//console.warn('relatedNode = body');
		} else if (userJSEvent.event.target && userJSEvent.event.target.nodeName === 'BODY') {
			//console.warn('target = body');
		}
		if (document.body) {
			//console.info('body exists, running readReplacer, event:' + userJSEvent.event.type);
			readReplacer();
		}
	};

	loadingReplacer = function (event) {
		//console.log('loadingReplacer');
		if (event.relatedNode.nodeName === 'BODY') {
			//console.warn('relatedNode = body');
		} else if (event.target.nodeName === 'BODY') {
			//console.warn('target = body');
		}
		if (document.body) {
			//console.info('body exists, running readReplacer');
			readReplacer();
		}
	};

	readReplacer = function () {
		var readImgs = document.querySelectorAll(".post .seen2 .postbody img, .post .seen1 .postbody img"),
			allImgs,
			i,
			img,
			a,
			sa_pattern = /https?:\/\/\w*\.?somethingawful\.com\//,
			src;

		if (readReplacerRun) {
			return;
		}

		document.removeEventListener('DOMNodeInserted', loadingReplacer, true);
		opera.removeEventListener('BeforeEvent', beforeReplacer, true);


		for (i = 0; i < readImgs.length; i++) {
			img = readImgs[i];
			if (sa_pattern.test(img.src)) { // skip emoticons and avatars
				continue;
			}
			src = img.src;
			img.src = '';
			img.removeAttribute('src');

			a = document.createElement('a');
			a.href = src;

			a.target = '_blank';
			a.textContent = src;
			img.parentNode.replaceChild(a, img);
		}

		//console.log('stopping');
		window.stop();

		allImgs = document.querySelectorAll("img");

		//console.log('resetting remaining image src');
		for (i = 0; i < allImgs.length; i++) {
			img = allImgs[i];

			src = img.src;
			img.src = '';

			//console.log('src:' + src);
			img.src = src;
		}
		readReplacerRun = true;
		window.removeEventListener('DOMContentLoaded', readReplacer);
	};

	opera.addEventListener('BeforeEvent', beforeReplacer, true);
	document.addEventListener('DOMNodeInserted', loadingReplacer, true);
	window.addEventListener('DOMContentLoaded', readReplacer, false);

	if (document.readyState === 'complete' || document.readySate === 'loaded' || document.readyState === 'interactive') {
		window.removeEventListener('DOMContentLoaded', readReplacer);
		readReplacer();
	}
}());
And here is the non-trainwreck version, if someone else wants read images in the PYF gif thread to be links.
JavaScript code:
// ==UserScript==
// @name read gifs to links
// @description Make gifs in read messages into links on some of Something Awful's image heavy threads
// @include http://forums.somethingawful.com/showthread.php*threadid=3457178*
// ==/UserScript==
/*jslint browser: true, plusplus: true, continue: true */

(function () {
	"use strict";
	var readReplacer;

	readReplacer = function () {
		var readImgs = document.querySelectorAll(".post .seen2 .postbody img, .post .seen1 .postbody img"),
			i,
			img,
			a,
			sa_pattern = /https?:\/\/\w*\.?somethingawful\.com\//,
			src;

		for (i = 0; i < readImgs.length; i++) {
			img = readImgs[i];
			if (sa_pattern.test(img.src)) { // skip emoticons and avatars
				continue;
			}
			src = img.src;
			img.src = '';
			img.removeAttribute('src');

			a = document.createElement('a');
			a.href = src;

			a.target = '_blank';
			a.textContent = src;
			img.parentNode.replaceChild(a, img);
		}

		window.removeEventListener('DOMContentLoaded', readReplacer, false);
	};

	window.addEventListener('DOMContentLoaded', readReplacer, false);

	if (document.readyState === 'complete' || document.readySate === 'loaded' || document.readyState === 'interactive') {
		window.removeEventListener('DOMContentLoaded', readReplacer, false);
		readReplacer();
	}
}());

Hughlander
May 11, 2005

It looks like the next two weeks at work I need to work on a Node.js program with custom C++ classes. What's the recommended IDE/debugger for such a beast? Bonus points if I can set a break point in JS and step into the C++ and back out again with the return value.

Lurchington
Jan 2, 2003

Forums Dragoon
this is not a question at all, but I personally have been working on a home javascript app and I was really struggling with how to unittest.

Ended up going with a combination of qunit and js test driver using the qunit to js test driver adapter and I think it looks great.

It's a little harder to write "good" unit tests for ajax that work on both regular qunit (nice in-browser test runner) and js test driver (for continuous integration build failing), but I think I "iteratively developed" something there that I'm happy with. So figured I'd share that if you're doing java, and need unit tests I think qunit and/or js-test-driver could work for you.

repo after making that change for seeing how I combined it, but nothing that makes sense without some amount of background knowledge in qunit/js test driver

edit: for IDEs, I'd say WebStorm since I'm a huge Pycharm user (which does all the javascript stuff too) and like Jetbrains products.

Boz0r
Sep 7, 2006
The Rocketship in action.
I'm trying to get a function called every time a checkbox is changed and it's driving me nuts.

This is my code:
code:
checkbox.onclick(OnChangeCheckbox (this));

function OnChangeCheckbox (checkbox) {
   if (checkbox.checked) {
      alert(allowCookies);
   } else {
      alert(allowCookies);
   }
}
When I try to check whether the script is assigned in Chrome, it just gives me this:
code:
document.getElementById("checkbox").onclick

null
What gives?

EDIT: It tells me this:
code:
TypeError: Property 'onchange' of object #<HTMLInputElement> is not a function

Boz0r fucked around with this message at 11:02 on Nov 5, 2012

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

Boz0r posted:

I'm trying to get a function called every time a checkbox is changed and it's driving me nuts.

This is my code:
code:
checkbox.onclick(OnChangeCheckbox (this));

function OnChangeCheckbox (checkbox) {
   if (checkbox.checked) {
      alert(allowCookies);
   } else {
      alert(allowCookies);
   }
}
When I try to check whether the script is assigned in Chrome, it just gives me this:
code:
document.getElementById("checkbox").onclick

null
What gives?

EDIT: It tells me this:
code:
TypeError: Property 'onchange' of object #<HTMLInputElement> is not a function

code:
checkbox.onclick(OnChangeCheckbox (this));
Actually does this:

1) You call the function OnChangeCheckbox with this.
2) you then call the function onclick (which is probably null) of checkbox with whatever OnChangeCheckbox returned (which is probably undefined, or because it looks like OnChangeCheckbox is undefined when you call it, it will just throw an error)

What you probably want is to declare OnChangeCheckbox first, then assign: checkbox.onclick = OnChangeCheckbox;

And for the love of god, use console.log instead of alert if you need to dump some variable.

e: And when OnChangeCheckbox is called after checkbox.onclick, this will point to the checkbox.

Wheany fucked around with this message at 12:55 on Nov 5, 2012

Adbot
ADBOT LOVES YOU

Spatulater bro!
Aug 19, 2003

Punch! Punch! Punch!

In other words, you don't want to call the function as an argument of onclick, you need to assign the function to onclick. Right?

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply