Latest Project

cafe rio iphone app

Testimonials

Banner

Blog Tags

Lab Eleven Blogs

Web design & Programming tutorials
Category >> Web Design

Using an Image as a Submit Button in HTML

Posted by: twmeier

Tagged in: Javascript , HTML

There are times when you want to use an image as a button to submit a form. One case is when you need to use JavaScript to check the html form was submitted correctly. Here is the code:

<script>
    function checkForm()
    {
        var msg = "Please correct the following: \n\n";
        var error = false;
       
        if(document.formName.elementName.value=="") {
            msg += "You must enter a date.\n";
            error = true;
        }
       
        if(error){
            alert(msg);           
        }else{
            if(confirm("Are you sure you want to submit this form?")){                                               
                document.formName.submit();       
            }                   
        }
    }
</script>

<form name="formName" action="/index.php?&task=something" method="post">
    <input type="text" name="elementName" id="elementId" value="">
    ....
</form>


<a href="#" onclick="checkForm(); return false;"><img src="/images/brown_submit.jpg" /></a>


The method above works in all browsers, and is easy to use. When you click the image, the JavaScript function is called. If there are no errors in the form, the function submits the form. Its that easy.


Changing a New Line to a Break

Posted by: twmeier

Tagged in: PHP

There is a great php function takes a variable and changes the  new lines (\n) into breaks (<br/>).

For example, a user submits a form on your website and used a textarea to submit a couple of paragraphs. You then retrieve this data from the database and echo it out in html. You will notice that it is now just one big paragraph.

To fix this problem, you the function: nl2br

Here is how you might use this:

<?php
     $paragraphs = nl2br($paragraphs);
     echo $paragraphs;
?>


Cleaning Up After a WYSIWYG Editor

Posted by: jstartup

Tagged in: JCE Editor , HTML

For basic content edits a WYSIWYG editor is a great tool to have.  The HTML it generates, however, is not so great.  Sometimes there's a chunk of text that it just doesn't seem to want to make changes to, and the reason is usually that style tags were left behind from previous changes.  The good news, though, is it's not difficult to clean up HTML.  Doing so will restore content to its default state, and will make it respond to the editing tools the way it should.


How to Stop a Form From Submitting on Enter

Posted by: twmeier

Tagged in: Javascript , HTML

I came across a problem this week, with a form that submitted when a user hit the "enter" or "return" button even though the submit button had an onclick function that should have kept the form from submitting. The problem only manifested itself on Google's Chrome browser.

I found the following JavaScript code to keep this from happening:

// Disables enter button from submitting the form
    var nav = window.Event ? true : false;
    if (nav) {
       window.captureEvents(Event.KEYDOWN);
       window.onkeydown = NetscapeEventHandler_KeyDown;
    } else {
       document.onkeydown = MicrosoftEventHandler_KeyDown;
    }
    function NetscapeEventHandler_KeyDown(e) {
      if (e.which == 13 && e.target.type != 'textarea' && e.target.type != 'submit') { return false; }
      return true;
    }
    function MicrosoftEventHandler_KeyDown() {
      if (event.keyCode == 13 && event.srcElement.type != 'textarea' && event.srcElement.type != 'submit')
        return false;
      return true;
    }

 
This worked great and fixed my problem (and hopefully your too).


Image Alignment in JCE

Posted by: jstartup

Tagged in: JCE Editor

By default the JCE Editor will insert an uploaded image into a content area separated from the text before and after it.  This is passable on a particularly wide image, but most common is to wrap the text around any images in the content.  In order to set this up well there are some parameters to get to know.


Opening a New Browser Window

Posted by: twmeier

Tagged in: Javascript , HTML

There are times when you may want to open a page in a new browser window. You may also want to be able to determine the size of the new window, whether or not to have scroll bars, tool bars,  status bars etc..  There is a ready-made JavaScript function that you can use to do this:

window.open('url', 'window name', 'attribute1', 'attribute2', .....)

  1. 'url'
    This is the url of the page you would like to appear in the new window.
  2. 'window name'
    You can name your window whatever you like, which can be used if you need to make a reference to the window later.
  3. 'attributes'
    Attributes determine how the new window will look, and are listed below.

Attributes



Discover Your Future Site

Posted by: gbluma

Tagged in: Web Design

camera_smallSo you want to revamp your current site right? Or maybe you want a new site but can't put your finger exactly on what you need.

Here are a few things to consider which might help you decide on the details. I'll also run through a test scenario of a small photography company as an example.

Website Design: A Bit About Fonts

Posted by: jstartup

Tagged in: Web Design

Fonts can be grouped in four main categories: basic, scripted, stylized and shapes.  The basic category is used most often for large amounts of text, and particularly for websites since browser cross-compatibility is a high priority in web design.  This group contain familiar fonts such as Arial, Times New Roman and Courier New,  the most web-friendly choices.  Also commonly used are Georgia, Verdana and Helvetica, and any of them will display a large amount of text nicely and offer a design a classic, sophisticated look.


Web Page Layout: Using a Grid

Posted by: jstartup

Tagged in: Web Design

Grid-based layout is a simple method for structuring an effective web page.  Balance is easy to maintain, and there is a common element running from page to page without having to stucture each the same way.  So, for instance, a website with the content area set to 960x680 could be set up as one of the layouts shown below.


Latest Blogs

Will iPhone Apps Run On iPad?
Jan 29th 2010 by: Trevor M.

How to create a marquee text for an iPhone app
Jan 21st 2010 by: Trevor M.

How to Submit Additional Images in Virtuemart
Aug 7th 2009 by: Trevor M.

Using an Image as a Submit Button in HTML
Jul 31st 2009 by: Trevor M.

Joomla 1.5 Custom Breadcrumbs
Jul 9th 2009 by: Garrett Bluma

Read all blogs