Thu, 15 Mar 2007
IBM's developerWorks - JavaScript and Ajax Tutorial Series
One of my often visited bookmarks is IBM's developerWorks
site. The site is virtual library of technical information and tutorials.
In September 2006, Brett McLaughlin, Author and Editor with O'Reilly Media Inc, concluded his six part
series on JavaScript, Ajax and the Document Object Model (DOM). Part one of the series starts with a
quick-paced introduction to what Ajax is and how it works, follows with the use of the XMLHttpRequest object
for Web requests and understanding the HTTP status codes it returns. The remaining parts of the series focus
on how to mix JavaScript and the DOM to create interactive Ajax applications.
It is a great series that I still reference now and then when in the midst of a project.
posted: 21:23 | 0 comments | tags: ajax, javascript, programming
Tue, 14 Mar 2006
Formating Numbers in a Text Box
I recently needed to control the format that was being entered into a text box on a form. I needed the user to enter a currency amount, however, I did not want dollar signs, commas or decimal places to be entered. I simply wanted the raw number.
This is one way to do it.
<html>
<head>
<title>Number Format</title>
<script language="JavaScript">
function formatNumber(e, field) {
key=e.keyCode;
// Allow use of return, left and right cursor keys
if ((key==13)||(key==37)||(key==39)) return;
temp=field.value.replace(/[^0-9]|^0+/g,"");
field.value=temp;
}
</script>
</head>
<body>
<form name="form1" method="post" action="">
Enter Salary:
<input type="text" name="amount" id="amount"
onKeyUp="formatNumber(event, this)">
</form>
</body>
</html>
The script is called on the "onKeyUp" event of the input field and strips out any character that is not a number.
posted: 00:38 | 0 comments | tags: javascript, programming
Mon, 13 Mar 2006
URL Rewriting in JavaScript
At work I am constantly flipping between a production and a development web server. The live site would have a URL like, "www.mysite.com" and the development site one like, "dev.mysite.com". I was getting tired of removing the "www" from the address and replacing it with "dev" and back again for all the different URLs. This script is a result of that. By simply clicking a saved bookmark on my browser toolbar I can automatically switch back and forth between the production and development servers with ease.
Right-click on the following link, DevSwitch, and select either "Bookmark This Link..." in FireFox or "Add to Favorites..." in Internet Explorer.
The Bookmarklet code is outlined below.
javascript:(function(){
x=location.href;
y=(x.indexOf('www')!=-1)?x.replace('www','dev'):x.replace('dev','www');
location.href=y;
})()
posted: 23:58 | 0 comments | tags: bookmarklet, javascript, programming