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
jupo
Jun 12, 2007

Time flies like an arrow, fruit flies like a banana.

There Will Be Penalty posted:

This means you can write code such as the following:

code:
var visible;                    /* a boolean */
/* ... */
$("#div0")[visible ? "show" : "hide"]();

I personally can't stand this type of thing. Just because it's clever doesn't mean you should do it. When someone comes back 6 months later to read thousands of lines of code like this it's just a nightmare when it's not at all obvious what's happening without having to mentally pause for every bit of cleverness to figure it out. Use an if statement and write explicit and readable code where what's happening is instantly recognizable without even having to think.

Adbot
ADBOT LOVES YOU

jupo
Jun 12, 2007

Time flies like an arrow, fruit flies like a banana.

Blackout posted:

Hi guys, quick question for you. I've got a whole bunch of xml files which use a stylesheet to be displayed as HTML. The files are organized by folder on my computer, so that the structure looks something like this:

Main Folder
--Folder A
----1.xml
----2.xml
----3.xml
--Folder B
----4.xml
----5.xml
--Folder C
----6.xml
----7.xml

The number of files in each folder as well as the number of folders themselves can change, so I'd like to try and dynamically build a link tree. Using javascript to create the tree and the links is easy enough, but I'm stuck trying to figure out how to grab the names of these files/folders. I've found a bunch of stuff about the Scripting.FileSystemObject ActiveX object, but it seems to be pretty useless because of the security constraints and the fact that Firefox doesn't seem to support it. Do any of you know of any other methods I could use to list all of the files and folders residing under the Main Folder?

Thanks in advance!

Gonna assume you're talking about javascript in the browser since you mentioned Firefox. What you're trying to do here is traditionally a server-side thing with languages like PHP or ASP, and not done in the browser. If you're hosting your site on IIS then you are actually able to write ASP code using javascript and the FileSystemObject but this all runs on the server and security constraints aren't relevant here.

If you have no sever-side programming ability and you're a true masochist you could potentially try and do something that uses ajax to parse directory listing pages on the server and build the tree from that, but don't.

jupo
Jun 12, 2007

Time flies like an arrow, fruit flies like a banana.

Blackout posted:

Thanks for the advice, jupo! I guess I'll try to use IIS to do some server-side scripting with ASP or something.

No problem! Being able to write javascript on both the client and server is actually a really nice environment to work with.

jupo
Jun 12, 2007

Time flies like an arrow, fruit flies like a banana.

aksuur posted:

Why won't my jquery load work in firefox? It work's in IE just fine.

http://geekforcheap.net/test/account.php

Use test/test for user/pass. When they logout, I'm using a jquery load to bring back the login form. Works fine in IE but not firefox.

code:
	function bringpage(id) {
		$("#page").load("" +id+ "");
	}
The logout link calls a js function, which first sends a GET to a php script to erase the cookie, then calls the bringpage function to load the login page into the page div (everything below the header). If this isn't enough of the code, let me know.

test/test isn't working with FF or IE bro.

jupo
Jun 12, 2007

Time flies like an arrow, fruit flies like a banana.

FrozenShellfish posted:

I'm making a nice website for a mobile library project in the Peruvian Andes, I tried to use javascript to make the forms easier to fill out and then I realised I don't have a clue what I am doing :(

This does what I want in firefox (adds/removes another row from the table) but it doesn't work at all in IE. Can someone fix it for me? Cheers.
http://new.bibliotecaurubamba.com/iesucks.htm

edit: fixed it very soon after I posted this: it didn't like the line "al.class='field'" for some reason

It'd be worth your while to check out jquery - using it you could probably reduce this down to a few lines of code as well as making it more cross-browser compatible.

jupo
Jun 12, 2007

Time flies like an arrow, fruit flies like a banana.

0zzyRocks posted:

I need to have the user decide whether they want to save data on a webapp before navigating away. I wanted to use my own confirm window so I could capture what button was clicked. Is there a way to capture the button clicked on the default beforeunload event popup?

Gmail seems to manage this - if you try and leave it before data finishes loading it presents you with a prompt that allows you to stay with the page even though you've requested to leave it.

Good luck making sense of viewing their source though!

jupo
Jun 12, 2007

Time flies like an arrow, fruit flies like a banana.

epswing posted:

Just thought I'd share a snippet I've gotten a lot of mileage out of:

code:
var url = function() {
	var url_regex = /^(?:([A-Za-z]+):)?(\/{0,3})([0-9.\-A-Za-z]+)(?::(\d+))?(?:\/([^?#]*))?(?:\?([^#]*))?(?:#(.*))?$/;
	var url = url_regex.exec(location.href);
	return {
		url: url[0], 	// [url]http://www.site.com:8080/subdir/search.html?q=help#top[/url]
		scheme: url[1], // http
		slash: url[2], 	// //
		host: url[3], 	// [url]www.site.com[/url]
		port: url[4], 	// 8080
		path: url[5], 	// /subdir/search.html
		query: url[6], 	// q=help
		hash: url[7] 	// top
	};
}();
Use it like this:
code:
alert(url.scheme + '://' + url.host + ':' + url.port); // "http://www.site.com:8080"
Credit goes to Crockford's The Good Parts.

The location object already has all these properties

jupo
Jun 12, 2007

Time flies like an arrow, fruit flies like a banana.
Aye matey.

Could still be useful as a function you pass urls into that aren't the current location.

Adbot
ADBOT LOVES YOU

jupo
Jun 12, 2007

Time flies like an arrow, fruit flies like a banana.
A more clean approach would be to pass the form to the validation function:

code:

function validateForm(form) {
    if(form.term.selectedIndex == 0)
    {
        alert("Please select an Item.");
        form.term.focus();
        return false;
    }
    return true;
}

<form onsubmit="return validateForm(this);" action="" method="post">
    <select name="term">
        <option>Pie</option>
        <option>Cake</option>
        <option>Poop</option>
    </select>
    <input type="submit" />
</form>

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