Thursday, May 15, 2008 by Admin
As mentioned earlier, user input plays a big role on webpages. It acts as an interface between users and the server. Handling user inputs is important as we need to ensure what data can be sent to the server and we cannot expect what the user will send. One of the most common things need to be checked is the input strings.
Strings in javascript is not hard but also not easy to be managed. String is an object in javascript and so a lot of methods have been designed to manipulate it but on the other hand, as an input type, it provides the most freedom to users. As a result, checking is also the most complicated with text input type.
This time, we take the start and trailing space in text input as an example. Users, mostly casual ones, sometimes input strings with these whitespaces in the input boxes without caring. It does’nt look much difference in a glance. However, in the server side point of view, these start and trailing space does make a lot difference. For example, for a query request and database update request, these spaces can lead to failure of potential hits in the search and failure in finding the existing database entry. So, removing these starting and trailing space is a very common practice. It can be done on the client side when user submit the data.
Sounds good! Wait! Javascript object does’nt provide the trim function! So, how? Actually, it’s not hard to make one trim function by yourself. The following is one of the examples using javascript regular expressions.
[Read More…]
Posted in Javascript | | (1395 views)
by Admin
As the internet is getting popular, people want to interact with webs more easily. Html Form is the main way for users to interact with server side. It can bring a lot of functionalities to web sites such as searching, data storing and different kinds of calculations. However, page involving user inputs also implies users can do something to your page. The page would not know what data the user would give and unsuitable and unexpected data could bring undesired behaviors to the program, poor program could even crash with inappropriate data. As a result, the idea of input checking and validation is important if user input is involved.
[Read More…]
Posted in General, Javascript | | (300 views)
Wednesday, May 14, 2008 by Admin
A lot of web programmers would want a easy way to handle files on the client machine to suit their designs, for example, storing a temporary config file to be retrieved each time when users visit their site(which can be easily achieved by using cookies), setting a default upload file with the from file type to show user what to upload, etc. Some of them could be cool ideas, but how can you achieve these using javascript?
[Read More…]
Posted in Javascript | | (1309 views)
Monday, May 12, 2008 by Admin
By reading a forum post on 110mb.com, I realized I did some kind of things like this and would like to share the tips with you. Sometimes, web designers want to do some ‘fancy’ stuff on their pages, for example, toggle and allow the display of certain elements (say a form, or pictures).It not only provides fancy feeling to users, but could also make them feel a clear and simple layout. And here’s how you do it.
[Read More…]
Posted in Javascript, Css | | (5277 views)