37 sites, 19,912 entries and counting...     Get a free blog; Join a Weblog Network!
Top

ASP.NET: Disable, Enable Validator Using Javascript

January 9, 2009

Doing this is pretty easy, if you know how or what method to use. I wanted to disable a Validator for a province TextBox if the country DropDownList chosen is USA because the state DropDownList will be enabled so the province should be inactive. Doing this server-side may be easy, but I wanted to use client-side Javascript so that no request will be sent whenever the OnChange event of the country’s DropDownList gets fired. Luckily, there is already a pre-made function in Javascript that disables Validators.

provinceValidator = document.getElementById(’ProvinceValidator’);
ValidatorEnable(provinceValidator, false);

Just set the second parameter as either true or false to enable and disable a Validator. I hope this will help those who have no clue how to go about it like I did until I found out about this function.

Email Using JavaMail

January 8, 2009

JavaMail, a technology from Java allows programmers to develop code that can send emails whether in plain text or HTML. Here’s a short easy code to send email to a recipient.

public static boolean send(String replyTo, String from_email, String to_email, String subject, String body, String type) {
boolean sent = false;
try {
Properties prop = new Properties();
prop.setProperty(”mail.smtp.localhost”, “localhost”);
prop.setProperty(”mail.smtp.port”, “25″);
Session session = Session.getDefaultInstance(prop);

Message msg = new MimeMessage(session);
msg.setSubject(subject);

InternetAddress from = new InternetAddress(from_email);
InternetAddress to = new InternetAddress(to_email);
msg.addRecipient(Message.RecipientType.TO, to);
msg.setFrom(from);

Multipart multipart = new MimeMultipart(”related”);

BodyPart htmlPart = new MimeBodyPart();
if (type.equals(”html”)) htmlPart.setContent(body, “text/html”);
else htmlPart.setContent(body, “text/plain”);

multipart.addBodyPart(htmlPart);
msg.setContent(multipart);

Transport transport = session.getTransport(”smtp”);
transport.connect(USERNAME, PASSWORD); // username, password to connect to smtp server
transport.sendMessage(msg, msg.getAllRecipients());
transport.close();

} catch (Exception e) {
System.err.println(”[MailTool] send() : ” + e.getMessage());
e.printStackTrace();
}

return sent;
}

Notice the line that says transport.connect(USERNAME, PASSWORD);

That line is optional in case you have set your SMTP server for authentication before emails are sent out by the mail server. The method also provides the option to let you send the email as plain text or HTML. Just set the value to html if you want it to be sent as HTML.

The Javascript Keyword var

January 8, 2009

I made this post to remind me that after so many years of using Javascript, I now know what the purpose of the keyword var really is for. The purpose for using the var keyword on a variable is to make it locally scoped. This means that if you use that inside a function, the variable’s scope is gone once the function is finished processing. I never noticed any difference with using a var or not simply because there never came a point in time that I would be having problems with the values of a variable. Until now. When I had problems with the values on a single variable, I was confused why. I tried to add the var keyword thinking, who knows right? And it worked! That was the time I decided to look up the purpose of the var keyword in Google and found the answer.

I laugh at myself why I discovered this until now after so many years. But hey, better late than never right? At least now I know he he he :D.

Hiding a div

October 15, 2008

I think there are a lot of people like you work a lot in code instead of design mode, for those in my situation, following a little tip to hide our big div that we create.
It will allow us to see the code a little clear and more easy to work, and of course, it can display the div again if you wish, here the code to add between .

function hide(link){
var objet = document.getElementById(’popup’); // entre les deux ‘ tu mes le nom du div que tu veux faire apparaître !
if(objet.style.display == “none” || !objet.style.display){
objet.innerHTML = “Ici le text que tu veux faire apparaître !”;
objet.style.display = “block”;
objet.style.overflow = “hidden”;
link.innerHTML = “-”;
var hFinal = 200; //Hauteur finale (la hauteur une fois que ça aura fini de déplier !)
var hActuel = 0; //Hauteur initiale (la hauteur dès le début !)
var timer;
var fct = function () {
hActuel += 20; //Augmente la hauteur de 20px (tu peux modifier) tous les 40ms !

objet.style.height = hActuel + ‘px’;

if( hActuel > hFinal)
{
clearInterval(timer); //Arrête le timer
objet.style.overflow = ‘inherit’;
} };
fct();
timer = setInterval(fct,40); //Toute les 40 ms
}else if(objet.style.display == “block”){
var hFinal = 0; //Hauteur finale (la hauteur une fois que ça aura fini de déplier !)
var hActuel = 200; //Hauteur initiale (la hauteur dès le début !)
var timer;
var fct = function () {
hActuel -= 20; //Augmente la hauteur de -20px (tu peux modifier) tous les 40ms !
objet.style.height = hActuel + ‘px’;
if( hActuel < hFinal) {
clearInterval(timer); //Arrête le timer
objet.style.overflow = ‘inherit’;
objet.style.display = “none”;
} };
fct();
timer = setInterval(fct,40); //Toute les 40 ms
link.innerHTML = “+”;

} }

Following the code to be addedd between

[+]

Over there my friend !!!

Hope it will be useful for everybody

Practical Javascript, DOM Scripting, and Ajax Projects

December 20, 2007

Practical Javascript, DOM Scripting, and Ajax Projects picks up where Beginning JavaScript with DOM Scripting and Ajax left off.

Frank Zammetti’s practical guide to real-world JavaScript and Ajax will have you developing actual client-side apps in no time. As more of a hacker than a theoretician, this kind of guide appeals to me. Usually when I start developing my own apps, some of the code used previously (in building sample apps) will be adapted and tweaked for my own purposes.

Some of the projects you’ll learn how to build in Practical Javascript:
* JSDigester - a library that simplifies (takes away the pain) of parsing XML on the client side
* Mashing up a list of hotels + a Yahoo Map for a user-entered zipcode
* Client-side persistence techniques
* A JavaScript validation framework
* Building widgets and working with UI widget frameworks
* Building a JavaScript mini-game (cool!)
* An Ajax-based client-server chat pplication

You can pick up a copy of Practical Javascript, DOM Scripting, and Ajax Projects at Amazon.com (avg. review score is 4.5 stars).

Beginning JavaScript with DOM Scripting and Ajax

December 15, 2007

Beginning JavaScript with DOM Scripting and Ajax will take you from knowing absolutely nothing about JavaScript to being able to manipulate the DOM, build basic Ajax applications and more.

Most of us who have been building websites since the pre-Ajax days learned JavaScript through a mish-mash of one-off scripts, validations, etc. If a book like this had been around, it surely would’ve offered a nice clean overview of the techniques available to the JavaScript programmer.

Luckily for the novice JavaScript programmer (or intermediate developer wishing to hone his craft), Beginning Javascript with DOM Scripting and Ajax does exist now and is the perfect way to learn the fundamentals from the ground up. The 2nd part of the book also focuses on Ajax and some of the interesting hacks one can use in that realm.

The author, Christian Heilmann, has a geeky sense of humor that keeps the reading light — for eaxmple Et Tu, Cache? (pg. 309):

Safari is the main offender as it caches the response status and does not trigger the changes (remember that the status returns the HTTP code 200, 304 or 404) any longer.

Adding this snippet tells the browser to test whether the data has changed since a certain date, i.e.:

request.setRequestHeader( ‘If-Modified-Since’, ‘Thu, 06 Apr 2006 00:00:00 GMT’);
request.send( null );

A bit out of context here, but just one example of the kind of thing you’ll find in Beginning JavaScript with DOM Scripting and Ajax.

Ajax script resources

May 15, 2006

Working with Ajax? (Asynchronous Javascript and XML) Especially in web applications? Check out the web applications and scripts, coding secrets, and tips on the following web sites. As Ajax grows, so will these resources, so its highly recommended to bookmark them:  (also great sites for HTML codes, CGI, Perl, Javascript, XML, and other coding scripts)

The Javascript Source:  http://javascript.internet.com/ajax/

The Javascript Forum: http://www.webdeveloper.com/forum/forumdisplay.php?s=&forumid=3

Ajaxed: http://www.ajaxed.com/

Ajax.net: http://www.ajaxpro.info/default.aspx?old=ajax&ref=http%3a%2f%2fwww.google.com%2fsearch%3fhl%3den%26q%3dFree%2bAjax%2bscripts

Open Cube: www.opencube.com

Javascript Kit: www.javascriptkit.com

and don’t forget my Yahoogroups web-design support group at www.yahoogroups.com/ “web-design”

 

 

 

Record a web-browsing session using neato AJAX-powered “web recorder”

April 16, 2006

TAPEFAILURE

This is an application which feels like it must surely have a useful purpose. I’m not totally sure what that use would be though. Perhaps recording a demo or walk-through of a website.

From the site:

TAPEFAILURE is a “history recording tool.” What this means is that anyone can record a browsing session using TAPEFAILURE’s recorder, then save it, and share it with others. Each recorded session can be played back virtually perfectly through our playback tool; as long as you know the tape ID or have a link, you can view your recorded session over and over again.

Overall, the site is attractively designed, very simple to get started, and seems like it could be really useful. They should include a couple of example recordings with usage scenarios — the kind of thing that marketing people love to put all over the place, and probably the programmers think is totally obvious.
We did have a problem trying to record something on Ajax Blog — (got a “Precondition Failed” message from our web server).
Some issues I noticed:

  • No way to Preview or Play the recording before you Save it.
  • Loading Digg didn’t work correctly when recording (kept on reloading the home page)
  • Sometimes it felt a little bit slow

Overall, really neat concept, nicely executed, feels like a toy until we figure out the business model.

Oh yeah, and the AJAX functionality is pretty slick — the application does what it promises smoothly, without any downloads or additional steps needed by the user. It would be neat to see what the database info looks like to do the replays.

Check it out: TAPEFAILURE

(Via Digg)
What would you use it for?

WWJUA - Where Would Jesus Use Ajax?

December 3, 2005

There’s a good discussion going on over at Ajaxian about specific times when Ajax should or should not be used based on a posting by Alex Bosworth (10 Places You Must Use Ajax).

From Alex’s article:

For heavy use applications such as a webmail client or a blogreader, users have the luxury of time to learn new UI concepts, and the frustration of interacting with a slow interface. This kind of application is a perfect opportunity to leverage Ajax everywhere. The more frequently users use an application, the more Ajax should be powering that use.

However for most web applications, it doesn’t make any sense to use Javascript for everything or even anything. Ajax only really clearly helps in a limited set of circumstances; the web already worked pretty well before Ajax and there are a lot of pitfalls and drawbacks to using Ajax in web development. A straight html weblog works just fine without being generated dynamically on the client with a stream of asynchronous messages from the server. Plain old HTML also works great for documents, or navigating between documents. Simple or rarely used applications can get along fine without putting in a bunch of Javascript.

A good reminder for sure, that ultimately it is not the technology that should dictate developer choices, rather it should be whatever will best serve the customer (the users!)

Good discussion going on Ajaxian: 6 Places You Must Use Ajax

Ajax without the X? - Good article about combining a generic Javascript new script engine with some PHP to deliver simple AJAX interactions

November 22, 2005

If you’ve wrestled with the whole XMLHttpRequest part of AJAX you should read this article. It clearly explains the technique of appending a new Javascript SCRIPT tag into the body and using the results to display new or updated content.

But there is one problem with most of the current implementations of Ajax: it has one dependency, and that is the XmlHttpRequest object. Most modern browser, like Firefox, have inbuilt support for this object, but older browsers, like Internet Explorer 6, don’t have native support for this object. Luckily, IE 6 does support it, but it’s built in as an ActiveX control, which means your visitors get an ugly warning message about the possible danger of an ActiveX control, or in some cases it just doesn’t work at all.

In this tutorial, I will show you how to use Ajax without even having to use the XmlHttpRequest object.

Read the article: PHPit - Totally PHP - Ajax & PHP without using the XmlHttpRequest Object

Via digg where there’s some good discussion going on about this technique.

Next Page »

Renegade Motorhomes - Credit Card Consolidation - Debt Consolidation - Credit Consolidation
Bottom