Two Javascript Tricks: click() and trim()

Man my poor blog hasn’t been updated in quite some time. What on earth could I do to remedy that situation? Wait, I GOT IT! I’ll add a new post! :)

Here are two really simple but really useful JavaScript tricks.

#1

document.getElementById(x).click();

The above is handy when you want to programmatically click a button for the user based on whatever logic you write. I used it to fire some ATLAS (now called ASP.Net AJAX) animations after I validated some fields.

#2

Add the following to your JavaScript library to trim the white space from the beginning and end of your strings.

String.prototype.trim=function()
{
	return this.replace(/^\s*|\s*$/g,'');
}

The above allows you to do this: xString = xString.trim();

Check out this Wikipedia article on ‘trim’. There are examples on how to trim a string for numerous programming languages.

http://en.wikipedia.org/wiki/Trim_(programming)

Share and Enjoy:
  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Twitter
  • Google Bookmarks
  • LinkedIn
  • Reddit
  • Tumblr
This entry was posted in Web & Software Development and tagged . Bookmark the permalink.

2 Responses to Two Javascript Tricks: click() and trim()

  1. alison says:

    nice new intro. you are dusty reagan and you <3 computers!

  2. Dusty Reagan says:

    FACT! Dusty <3s Computers! It's as true as 1+1 = math. ;)

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>