I just updated http://www.whathuhstudios.com/press/2008/01/04/ajax-contact-form-quick-install/ to version 1.6, updated JQuery to 1.4, fixed some validation bugs, etc. It’s still simple and small. Go grab it. You’ll be glad. Maybe.

Tags: , , , , , , ,

Dreamweaver, thou hast failed me agian. As if your multiple, daily, unexplained, unrelated crashes weren’t enough, now you want to tell me you don’t understand object oriented PHP code?

This blew my mind for a while. I had a piece of code that looked like:

$gdi["header"] = username($update->username) . ' u.......

in a php include file. For some reason, Dreamweaver decided to interpret the “->” in my object as a “?>” when in design view. Now, I very rarely use design view, but I’d seen this happen enough that it bugged me. The internet was no help, as those search terms most often relate to something different.

Today it struck me. Even though the closing “?>” tag is optional for PHP files, and is even recommended against by many to alleviate the issue of extra white space, Dreamweaver gets confused. Once I threw a closing tag in my document, Dreamweaver confirmed that there was, in fact, no html in my file.

And now I can sleep easy. (and go back and remove my closing tags. I don’t give a shit what Dreamweaver thinks)

Edit: 12-17-2009 And now I sleep even easier, because I haven’t opened Dreamweaver for over 4 months. I feel like it’s a bigger accomplishment than beating alcoholism. (Not really. No hate mail please)

Tags: , , ,

Some Jquery tricks

development April 22nd, 2009

I have been using Jquery for a few months now, and have completely fallen in love with it. I’ve probably looked at hundreds of different pages, blogs, posts, plugins, and tricks over the time I’ve spent learning it. Here are a few of my favorite things to use it for.

Putting text labels in a password field

Password inputs mask the text in them, so having “Enter Password” inside the field won’t do much good. We can’t change the type of input on the fly, but we can make it disappear, and have another appear… Here’s how I’ve done this:

1.	$(".passflip").click(function() {
2.	  if ($(this).attr("type") == "text") {
3.	    $(this).hide();
4.	    $("#"+$(this).attr("id").slice(1)).show().focus();
5.	  }
6.	});
7.	$(".passflip").show();
8.	$(":password").hide();

And the HTML code:

1.   <input id="Tuser_pass" class="input passflip" style="display: none;"
        name="Tpwd" size="20" type="text" value="Enter Password" />
2.   <input id="user_pass" class="input" name="pwd" size="20"
        type="password" />

What we’re looking at here may seem messy at first, especially line 4 of the javascript code. Its not that bad. It takes the id of the passflip element that we clicked, removes the first character (giving us user_pass in this case), and shows and sets focus to that element. To the user, that text input will have “transformed” to a password input seamlessly.

The text input has an initial display of “none”. Also, in lines 7 and 8, we then hide all the password inputs (which are set to visible on page load), and show all the passflip inputs. This ensures that for those without javascript enabled, they will still be able to use the form as intented. The only difference, is that they won’t see the “Enter Password” information in the input, it will just be blank.

Friendly one time “clear this” function

1.	$(".clearThis").click(function() {
2.	   if ($(this).val() == $(this).attr("title")) $(this).val("");
3.	});
4.	$("#username").val($("#username").attr("title"));

and the html

1.   <input type="text" name="user_email" id="user_email"
       class="input clearThis"  size="20" tabindex="20"
       title="ENTER EMAIL" />

The value of this little gem may not be apparent at first, but it’s a perfect companion to the above mentioned function, and fails very gracefully on non-javascript enabled machines as well.

Instead of setting the value of the text box to display “ENTER EMAIL”, we simply set the title. What happens then, if javascript is enabled, is that the value will be set, displaying instructions to the user. the clearThis click function then checks to see if the two match, and if so, its likely the first time that input was clicked, and it clears the box for user input. If javascript is not enabled, the clearThis click function obviously cannot work, but the text input won’t have anything in it to clear anyway, so we have a double win.

This is all I have for now. I’ll post more sometime next week. Love live JQuery!

Tags: , , , ,

Another tool released into the wild today, this time useful to pretty much anybody who has ever left a comment or filled out a form:

http://whathuhstudios.com/javascript-character-count.html

This will count the characters in your text, or optionally, the number of words you’ve typed as well. Good for those late-night papers you’re trying to pass off as real effort with a 500 word minimum.

Tags: , , ,

I just updated http://www.whathuhstudios.com/press/2008/01/04/ajax-contact-form-quick-install/ to version 1.5, reworked with JQuery, and trimmed the size down to about 33% of what it used to be. Check it out for a quick and easy way to add some Ajax Class© to your website!

Tags: , , , , , , ,