Category: Web development

  • Clear default text from input boxes using Javascript

    Providing labels is a great way to help users interact with your website properly. I like to put instructional text inside text boxes to save space. Users get annoyed when the text inside the box they click on does not disappear when they are ready to type. Users do not want to backspace default instructional text before typing in boxes, so some code is required to make this happen.

    I would like to share two small Javascript functions. The first clears out default text box contents automatically when a user clicks on the box. The second restores the default instructional text if the user leaves the box empty.

    Implement these functions using onfocus=”wash(this);” and onblur=”checkWash(this);” on your text input control. You may want to avoid the second function on text fields where input is optional, so the user can leave the text box blank.

    function wash( anInput ){
    if(anInput.value == anInput.defaultValue) anInput.value = '';
    }

    function checkWash( anInput ){
    if(anInput.value == '') anInput.value = anInput.defaultValue;
    }

    Try it

    Look, I made a demo!


  • Classic ASP and Server.GetLastError in IIS7

    My classic ASP error logging scripts were dead in the water when I moved them to a Windows Server 2008 with IIS 7.0.

    Some code like this is useful to record errors in a database:

    dim objErrorInfo, errorStringStr
    set objErrorInfo = Server.GetLastError
    errorStringStr = objErrorInfo.File & ", line: " & objErrorInfo.Line & ", error: " & objErrorInfo.Number & " " & objErrorInfo.Description & ", " & objErrorInfo.ASPDescription & objErrorInfo.Category
    errorStringStr = replace( errorStringStr, "'", "''" )

    Instead of using the default 500 item in the list, create a new handler for status code 500.100. Point this at your script, and you should be all set to log errors.

    Another way is to enter the Error Pages module of the website profile, and click “Edit Feature Settings” on the right hand sidebar.

    This screen will appear:

    iis7getLastError

    Configure yours in a similar fashion, and Server.GetLastError will start working in your script.