A look at your most important design decision – font, and size

Let’s take a code break for a minute and discuss fonts, target audiences, and why a screen will never equal a piece of paper. When you are designing your pages, the choices that you make regarding fonts and font sizes are some of the most important. Why? First, computer screens by design are going to be harder on the eyes than paper, as paper reflects light, where computer screens emit light and are constantly being refreshed, this means that as a designer you should make every effort to ease the strain and make your site as readable as possible. Take a look at the image below:

The x-size, which is literally the size of the small x in the font family, where the point size is the distance from the top of the ascender to the bottom of the descender. This is the reason that some fonts just look bigger than others when you place them in your code using the same point size in your CSS. For a good example take a look below:

Hey I’m 12 point arial, how do I look?
Hey I’m 12 point times new roman, I know I was designed for newspapers, but how do I look on the screen?
Hey I’m 12 point veranda, how do I look on the screen?
Hey I’m 12 point tahoma, how do I look on the screen?

There you have it, not only does size matter, font style plays an equally important role, but that’s not all …

Notice that some of the fonts are Serif, with the small lines on the ends of the characters, and some are Sans Serif, without the decoration. So what does this mean to the programmer? For the web designer, it’s easier on your audience if you go with a sans-serif font style, which is the opposite of traditional printing. The reason is the dots per inch or dpi on a screen is much less than the dpi when printing, the fonts seem to scale better.

Everything you need to know about web standards and design in 3 minutes!

I am working on updating some slides for an upcoming HTML course and stumbled across this brilliant video that explains everything you need to know in about three minutes, including why you need to use a standards based approach to design.

Here’s the lyrics

Your site design is the first thing people see
it should be reflective of you and the industry
easy to look at with a nice navigation
when you can’t find what you want it causes frustration
a clear Call to action to increase the temptation
use appealing graphics they create motivation
if you have animation
use with moderation
cause search engines can’t index the information
display the logos of all your associations
highlight your contact info that’s an obligation
create a clean design you can use some decoration
but to try to prevent any client hesitation
every page that they click should provide and explanation
should be easy to understand like having a conversation
when you design the style go ahead and use your imagination
but make sure you use correct color combinations
do some investigation, look at other organizations
but don’t duplicate or you might face a litigation
design done, congratulations but it’s time to start construction
follow these instructions when you move into production
your photoshop functions then slice that design
do your layout with divs make sure that it’s aligned
please don’t use tables even though they work fine
when it come to indexing they give searches a hard time
make it easy for the spiders to crawl what you provide
remove font type, font color and font size
no background colors, keep your coding real neat,
tag your look and feel on a separate style sheet
better results with xml and css
now you making progress, a lil closer to success
describe your doctype so the browser can relate
make sure you do it great or it won’t validate
check in all browsers, I do it directly
gotta make sure that it renders correctly
some use IE, some others use Flock
some use AOL, I use Firefox
title everything including links and images
don’t use italics, use emphasis
don’t use bold, please use strong
if you use bold that’s old and wrong
when you use CSS, you page will load quicker
client satisfied like they eating on a snicker
they stuck on your page like you made it with a sticker
and then they convert now that’s the real kicker
make you a lil richer, your site a lil slicker
design and code right man I hope you get the picture
what I’m telling you is true man it should be a scripture
if it’s built right you’ll be the pick of the litter
everyone will want to follow you like twitter
competition will get bitter and you’ll shine like glitter
if you trying to grow your company will get bigger
design and code right man can you get with it

Using Ext.DomQuery and ajax request to validate and submit plain old HTML forms



So you need to create a quick form which would be easy in plain old HTML but you want to throw in some client side validation, just the thing that javascript packages excel in. Your choices you think are to go ahead and overcomplicate your form by writing it in javascript using the packages and then heavily modifying the CSS to get just the right look (and we all know the number of DOM elements seems to increase exponentially when doing it this way) OR spending time rewriting validation functions that you know are built in if you were just able to get ext to look right! I built the following reusable validation and form submission function using some of ext’s util methods as well as some good old fashioned javascript, since all of the names are referenced by Ext’s DomQuery it becomes an abstract method that could be dropped into any project and connected to any form. Right now I am only making sure that there is text in any given field, however, I am sure with a bit of creativity you can extend this to work with all types of validation requirements! (hint: look into Ext.isNumber(), Ext.isDate() etc.. in the Ext util functions. And then think about the fact that you could make up your own attribute, for example vtype=”crazy_number”). First, we need a HTML form, so for this example the code below will render the form that you see here.

<form id="test_form" method="post " action="some_test.php">

<label for="first_name" >First  Name </label><img style="visibility:hidden" src="ext-3.2.1/resources/images/default/form/exclamation.gif" name="first_name_error" />
<input name=" first_name " type="text" onkeyup="javascript:changeStyles(this);" />

<label for="last_name" ><img style="visibility:hidden" src="ext-3.2.1/resources/images/default/form/exclamation.gif" name="where_from_error" />Where are you from? </label>
<select name="where_you_from"  >		
<option value="here" >Here</option>
<option value="there" >There</option>
<option value="everywhere" >Everywhere</option>
</select>

<input type="button" onclick="javascript:sf()" value="Save" style="width:100px;float:right;margin-top:15px;" class="x-panel-btns"  />
</form>
<br><br>&nbsp;

The form above is pretty straight forward, no fancy code, however, you will notice that there is a javascript function in the onclick event of our ‘submit’ button, and in fact there is no real submit button in the html sense. There are also functions on all of the text fields and text areas in the onKeyUp event which will alert the users to the fact that all fields in the form are mandatory. This is done via some CSS that which pulls from the Extjs library to give the invalid boxes the fancy red squiggly line and exclamation point when a value has not been entered and the user tries to press the submit button. The CSS that is required is below, just modify the path to the images to match your Extjs path.

var valid_style = '{border: 1px solid;background-color:#fff;border-color:#ccc;background-image:url(nothing.gif);padding-top:2px;padding-bottom:2px;}';
var invalid_style = '{border: 1px solid;background-color:#fff;background-image:url(/ext-3.2.1/resources/images/default/grid/invalid_line.gif);padding-top:2px;padding-bottom:2px;background-position:center bottom;background-repeat:repeat-x;border-color:#ccc;}';
var ex_pt_show = '{background-image:url(/ext-3.2.1/resources/images/default/form/exclamation.gif);background-repeat:no-repeat;}';
var ex_pt_hide = '{background-image:url(nothing.gif);background-repeat:no-repeat;}';

Next, the javascript that will fire when you submit the form and make sure that everything is valid before updating your back end database. Since you will be using ext to crawl the DOM you can add as many fields as you want to the code below and all you have to do is pass the form name into the validation function.

Ext.onReady(function(){

changeStyles = function(item){
   if ( item.value.trim().length==0){
	Ext.get(item.name).applyStyles(invalid_style);
	doSubmit = false;
	} else {
	Ext.get(item.name).applyStyles(valid_style);
	Ext.get(item.name + '_label').applyStyles(ex_pt_hide);
    }
 }	
function validation(form_id){
// Get all of the form elements		
var textBoxes = Ext.DomQuery.select('form[id=' +  form_id + '] >input[type=text]');  
var selectBoxes = Ext.DomQuery.select('form[id=' +  form_id + ']>select');  
var textAreas = Ext.DomQuery.select('form[id=' +  form_id + ']>textarea');
var doSubmit = true;
Ext.each(textBoxes,function(item,i){   
	// lets loop through the textfields and see if they have values
	if (item.value.trim().length==0){
		Ext.get(item.name).applyStyles(invalid_style); 
		doSubmit = false;
	} else {
		Ext.get(item.name).applyStyles(valid_style);
		Ext.get(item.name + '_label').applyStyles(ex_pt_hide);
	}
}); // end of loop through text fields
Ext.each(selectBoxes,function(item,i){   
	if (item.value.trim().length==0){
		Ext.get(item.name).applyStyles(invalid_style); 
		doSubmit = false;
	} else {
		Ext.get(item.name).applyStyles(valid_style);
		Ext.get(item.name + '_label').applyStyles(ex_pt_hide);
	}	
});
Ext.each(textAreas,function(item,i){   
	// lets loop through the text areas and see if they have values
	if (item.value.trim().length==0){
		Ext.get(item.name).applyStyles(invalid_style); 
		doSubmit = false;
	} else {
		Ext.get(item.name).applyStyles(valid_style);
		Ext.get(item.name + '_label').applyStyles(ex_pt_hide);
	}	
}); // end of loop through text areas
return doSubmit;
}
sf =  function(form_id){				
var doSubmit = validation(form_id);
if(doSubmit == true){
    alert('I would have submitted the form in real life!');
} else {
        alert('Please fill out all required forms!');
}
}
});

Note: The example form in this post only performs the validation on click, but you can see the code above for the implementation of a fully functional submit button.

Building a menu on top of Jon Rohan’s Triangles in CSS post with facebook style callouts using javascript for animation

Jon Rohan posted an excellent article on the ability to create triangles and other shapes simply by manipulating the borders of div tags, as it turns out it’s not that hard to put a callout effect on any plain rectangular div without using images. The original post is here (http://jonrohan.me/guide/css/creating-triangles-in-css/) . So what about taking this a bit farther and turning it into a fully fledged menu system where the selected element has the callout, and on rollover the callout follows your mouse up and down the menu? Take a look at the sample below, which will be explained in this post.

Try it out here: http://www.learnsomethings.com/testsomethings/rollover_tabs.html

First, there is the css that will give us the tabs, triangles, which when placed almost over one another form the callout, and the content boxes.

 
	body{
		font-family:Arial, Helvetica, sans-serif;
	}
	.chat-bubble:hover{
		cursor:pointer;
	}
	.chat-bubble {
	  background-color:#EDEDED;
	  border:1px solid #666666;
	  font-size:14px;
	  float:left;
	  line-height:1.3em;
	  margin:10px auto;
	  padding:5px;
	  
	  position:relative;
	  text-align:center;
	  width:120px;
	  -moz-border-radius:10px;
	  -webkit-border-radius:10px;
	  -moz-box-shadow:0 0 5px #888888;
	  -webkit-box-shadow:0 0 5px #888888;
	}
	
	.chat-bubble-arrow-border {
	  border-color: #666666 transparent transparent transparent;
	  border-style: solid;
	  border-width: 10px;
	  height:0;
	  visibility:hidden;
	  width:0;
	  position:absolute;
	  bottom:-21px;
	  left:30px;
	}
	
	.chat-bubble-arrow {
	  border-color: #2e6a8e transparent transparent transparent;
	  border-style: solid;
	  border-width: 10px;
	  visibility:hidden;
	  height:0;
	  width:0;
	  position:absolute;
	  bottom:-19px;
	  left:30px;
	}
	#content{
	display:block;
	width:500px;
	float:left;
	}
	
	.content_box{
	  width:100%;
	  height:300px;
	  border:1px solid #060;
	  float:left;
	}


Now, inside the tags of your page you will need to place the

tags that will make up the tab boxes, as well as the content panels that will be switched out on mouseover using javascript.

<body onload="javascript:hover('1');">
    	<div id="tab_panel">
            <div class="chat-bubble" name="1" id="1" onmouseover="javascript:hover(this.id)"  style="padding-left:10px;">
                Tab 1
              <div class="chat-bubble-arrow-border" id="1_tri" ></div>
              <div class="chat-bubble-arrow" 		id="1_arr" ></div>
            </div>
            <div class="chat-bubble" name="2" id="2" onmouseover="javascript:hover(this.id)" style="border-left:none">
                Tab 2
              <div class="chat-bubble-arrow-border" id="2_tri" ></div>
              <div class="chat-bubble-arrow"		id="2_arr" ></div>
            </div>
            <div class="chat-bubble" name="3" id="3" onmouseover="javascript:hover(this.id)" style="border-left:none;">
                Tab 3
              <div class="chat-bubble-arrow-border" id="3_tri"  ></div>
              <div class="chat-bubble-arrow" 		id="3_arr"  > </div>
            </div>
            <div class="chat-bubble" name="4" id="4" onmouseover="javascript:hover(this.id)" style="border-right:1px solid #666666;border-left:none;">
                Tab 4
             <div class="chat-bubble-arrow-border"  id="4_tri"  ></div>
              <div class="chat-bubble-arrow"  		id="4_arr"  ></div>
           </div>
       </div>
       <br clear="all"/>
       <div id="content">
       		<div id="content_1" name="content_1" class="content_box" style="display: none;background-color: #E5872C">
            	Page 1
            </div>
            <div id="content_2"  name="content_2" class="content_box" style="display: none; background-color: #3E4E6C">
            	Page 2
            </div>
            <div id="content_3"  name="content_3" class="content_box" style="display: none; background-color: #92CF00">
            	Page 3
            </div>
            <div id="content_4"  name="content_4" class="content_box" style="display: none; background-color:#333">
                Page 4
            </div>
       </div>
           
           
</body>

Finally, there is a script block that you need to put in the of your page right under the

tag that will control the changing of the tabs, callout triangles, and the main content.

<script>
	
	var last_hover_id = 1;
	
	function hover(id){
		
		var tri_obj= document.getElementById(last_hover_id + '_tri');
			tri_obj.style.visibility = "hidden";
		var arr_obj= document.getElementById(last_hover_id + '_arr');
			arr_obj.style.visibility = "hidden";
		
		document.getElementById(last_hover_id).style.backgroundColor = "#EDEDED";
		document.getElementById(last_hover_id).style.color = "#000";
		
		document.getElementById('content_' + last_hover_id).style.display = 'none';
		document.getElementById('content_' + id).style.display = 'block';
		
		var tri_obj= document.getElementById( id + '_tri');
			tri_obj.style.visibility = "visible";
	 	var arr_obj= document.getElementById( id + '_arr');
			arr_obj.style.visibility = "visible";	
		
		document.getElementById(id).style.backgroundColor = "#2e6a8e";
		document.getElementById(id).style.color = "#FFF";
		
		last_hover_id = id;
	}

</script>

You can see that the names of the content blocks as well as the id's of the tab boxes are no coincidence, this only works if the content boxes remain "content_x" and the id of each tab box is a numerical number that matches the content box.

The full source is here: http://www.learnsomethings.com/testsomethings/rollover_tabs.html

Setting multiple selected values in a html selectbox using javascript

I couldn’t find any really good answers to this question as most of the results when looking for this pertained to reading the multiple values versus setting the multiple values, so I thought I should post this piece of code. Assuming your multiple values are coming out of the database in the form of a comma delimited string [ 7,8,78,55 ] the following code will set the values using javascript.

// This is a great function I found @ 
// http://stackoverflow.com/questions/143847/best-way-to-find-an-item-in-a-javascript-array
// for determining
// if a value exists in an array.

function include(arr, obj) {  
	for(var i=0; i<arr.length; i++) {    
	if (arr[i] == obj) return true;   } 
}

var selections =  some_data_from_db; // this would be the data from the database
var selectedValues = new Array();
var your_sb      =  document.getElementById('id_of_sb');					
//if selections has a length then there is more than one category that was selected.
//there is a difference in how you have to handle multiple vs. sigle values selected.
if(selections.length){
	selectedValues = selections.split(',');
	for ( i = 0; i < your_sb.options.length - 1; i++){			
    if ( include(selectedValues, your_sb.options[i].value)){
	          your_sb .options[i].selected = true;  
	    } else {  
	         your_sb .options[i].selected = false;  							
	   }  
	} // end for loop
} else {	// this would be a single value									
        your_sb .value = some_data_from_db;							
}