Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

« Newer Snippets
Older Snippets »
Showing 21-36 of 36 total

Country dropdown HTML

<select>
<option value="AF">Afghanistanoption>
/option>
<option value="AL">Albaniaoption>
/option>
<option value="AS">American Samoaoption>
/option>
<option value="AO">Angolaoption>
/option>
<option value="AQ">Antarcticaoption>
/option>
<option value="AR">Argentinaoption>
/option>
<option value="AW">Arubaoption>
/option>
<option value="AT">Austriaoption>
/option>
<option value="BS">Bahamasoption>
/option>
<option value="BD">Bangladeshoption>
/option>
<option value="BY">Belarusoption>
/option>
<option value="BZ">Belizeoption>
/option>
<option value="BM">Bermudaoption>
/option>
<option value="BO">Boliviaoption>
/option>
<option value="BW">Botswanaoption>
/option>
<option value="BR">Braziloption>
/option>
<option value="BN">Brunei Darussalamoption>
/option>
<option value="BF">Burkina Fasooption>
/option>
<option value="KH">Cambodiaoption>
/option>
<option value="CA">Canadaoption>
/option>
<option value="KY">Cayman Islandsoption>
/option>
<option value="TD">Chadoption>
/option>
<option value="CN">Chinaoption>
/option>
<option value="CC">Cocos (Keeling) Islandsoption>
/option>
<option value="KM">Comorosoption>
/option>
<option value="CD">Congo, The Democratic Republic Of Theoption>
/option>
<option value="CR">Costa Ricaoption>
/option>
<option value="HR">Croatiaoption>
/option>
<option value="CY">Cyprusoption>
/option>
<option value="DK">Denmarkoption>
/option>
<option value="DM">Dominicaoption>
/option>
<option value="EC">Ecuadoroption>
/option>
<option value="SV">El Salvadoroption>
/option>
<option value="ER">Eritreaoption>
/option>
<option value="ET">Ethiopiaoption>
/option>
<option value="FO">Faroe Islandsoption>
/option>
<option value="FI">Finlandoption>
/option>
<option value="GF">French Guianaoption>
/option>
<option value="TF">French Southern Territoriesoption>
/option>
<option value="GM">Gambiaoption>
/option>
<option value="DE">Germanyoption>
/option>
<option value="GI">Gibraltaroption>
/option>
<option value="GL">Greenlandoption>
/option>
<option value="GP">Guadeloupeoption>
/option>
<option value="GT">Guatemalaoption>
/option>
<option value="GN">Guineaoption>
/option>
<option value="GY">Guyanaoption>
/option>
<option value="HM">Heard Island And Mcdonald Islandsoption>
/option>
<option value="HN">Hondurasoption>
/option>
<option value="HU">Hungaryoption>
/option>
<option value="IN">Indiaoption>
/option>
<option value="IR">Iran, Islamic Republic Ofoption>
/option>
<option value="IE">Irelandoption>
/option>
<option value="IL">Israeloption>
/option>
<option value="JM">Jamaicaoption>
/option>
<option value="JE">Jerseyoption>
/option>
<option value="KZ">Kazakhstanoption>
/option>
<option value="KI">Kiribatioption>
/option>
<option value="KR">Korea, Republic Ofoption>
/option>
<option value="KG">Kyrgyzstanoption>
/option>
<option value="LV">Latviaoption>
/option>
<option value="LS">Lesothooption>
/option>
<option value="LY">Libyan Arab Jamahiriyaoption>
/option>
<option value="LT">Lithuaniaoption>
/option>
<option value="MO">Macaooption>
/option>
<option value="MG">Madagascaroption>
/option>
<option value="MY">Malaysiaoption>
/option>
<option value="ML">Malioption>
/option>
<option value="MH">Marshall Islandsoption>
/option>
<option value="MR">Mauritaniaoption>
/option>
<option value="YT">Mayotteoption>
/option>
<option value="FM">Micronesia, Federated States Ofoption>
/option>
<option value="MC">Monacooption>
/option>
<option value="MS">Montserratoption>
/option>
<option value="MZ">Mozambiqueoption>
/option>
<option value="NA">Namibiaoption>
/option>
<option value="NP">Nepaloption>
/option>
<option value="AN">Netherlands Antillesoption>
/option>
<option value="NZ">New Zealandoption>
/option>
<option value="NE">Nigeroption>
/option>
<option value="NU">Niueoption>
/option>
<option value="MP">Northern Mariana Islandsoption>
/option>
<option value="OM">Omanoption>
/option>
<option value="PW">Palauoption>
/option>
<option value="PA">Panamaoption>
/option>
<option value="PY">Paraguayoption>
/option>
<option value="PH">Philippinesoption>
/option>
<option value="PL">Polandoption>
/option>
<option value="PR">Puerto Ricooption>
/option>
<option value="RE">Reunionoption>
/option>
<option value="RU">Russian Federationoption>
/option>
<option value="SH">Saint Helenaoption>
/option>
<option value="LC">Saint Luciaoption>
/option>
<option value="VC">Saint Vincent And The Grenadinesoption>
/option>
<option value="SM">San Marinooption>
/option>
<option value="SA">Saudi Arabiaoption>
/option>
<option value="CS">Serbia And Montenegrooption>
/option>
<option value="SL">Sierra Leoneoption>
/option>
<option value="SK">Slovakiaoption>
/option>
<option value="SB">Solomon Islandsoption>
/option>
<option value="ZA">South Africaoption>
/option>
<option value="ES">Spainoption>
/option>
<option value="SD">Sudanoption>
/option>
<option value="SJ">Svalbard And Jan Mayenoption>
/option>
<option value="SE">Swedenoption>
/option>
<option value="SY">Syrian Arab Republicoption>
/option>
<option value="TJ">Tajikistanoption>
/option>
<option value="TH">Thailandoption>
/option>
<option value="TG">Togooption>
/option>
<option value="TO">Tongaoption>
/option>
<option value="TN">Tunisiaoption>
/option>
<option value="TM">Turkmenistanoption>
/option>
<option value="TV">Tuvaluoption>
/option>
<option value="UA">Ukraineoption>
/option>
<option value="GB">United Kingdomoption>
/option>
<option value="UM">United States Minor Outlying Islandsoption>
/option>
<option value="UZ">Uzbekistanoption>
/option>
<option value="VE">Venezuelaoption>
/option>
<option value="VG">Virgin Islands, Britishoption>
/option>
<option value="WF">Wallis And Futunaoption>
/option>
<option value="YE">Yemenoption>
/option>
<option value="ZW">Zimbabweoption>
</select>

50 states dropdown HTML

<select name="state">
<option value="">Pick your stateoption>
/option>
<option value="AK">Alaskaoption>
/option>
<option value="AR">Arkansasoption>
/option>
<option value="CO">Coloradooption>
/option>
<option value="DE">Delawareoption>
/option>
<option value="FL">Floridaoption>
/option>
<option value="HI">Hawaiioption>
/option>
<option value="IL">Illinoisoption>
/option>
<option value="IA">Iowaoption>
/option>
<option value="KY">Kentuckyoption>
/option>
<option value="ME">Maineoption>
/option>
<option value="MA">Massachusettsoption>
/option>
<option value="MN">Minnesotaoption>
/option>
<option value="MO">Missourioption>
/option>
<option value="NE">Nebraskaoption>
/option>
<option value="NH">New Hampshireoption>
/option>
<option value="NM">New Mexicooption>
/option>
<option value="NC">North Carolinaoption>
/option>
<option value="OH">Ohiooption>
/option>
<option value="OR">Oregonoption>
/option>
<option value="RI">Rhode Islandoption>
/option>
<option value="SD">South Dakotaoption>
/option>
<option value="TX">Texasoption>
/option>
<option value="VT">Vermontoption>
/option>
<option value="WA">Washingtonoption>
/option>
<option value="WI">Wisconsinoption>
/option>
select>

Center something vert. and horz. in a web page using CSS

Here's how to center anything vertically and horizontally in a web page using CSS. Works with most all browsers that support CSS.

I adapted this from Jak psåt web, thanks!

<html>
        <head>
                <title>Center w/ CSStitle>
                
        
        
                
"outer">
"middle">
"inner"> your stuff here in center of page

add website to geourl

//add website to geourl
//long desciption on http://geourl.org/add.html

#1 get coordinates

#2 add meta tags to head
<meta name="ICBM" content="XXX.XXXXX, YYY.YYYYY">
<meta name="DC.title" content="THE NAME OF YOUR SITE">

#3 ping http://geourl.org/ping/

Disable a checkbox

Disable a checkbox via HTML or javascript.

<INPUT TYPE="checkbox" NAME="MyCheckbox" VALUE="Select Me" DISABLED>

document.forms[0].MyCheckbox.disabled = true;

Check / Uncheck all checkboxes in a pseudo group

This bit of javascript will check and uncheck all checkboxes in a group of checkboxes. The checkboxes are grouped by naming all the checkboxes by the same name.

Javascript Code:
function checkUncheckAll(checkAllState, cbGroup)
{
        // Check that the group has more than one element
        if(cbGroup.length > 0)
        {
                // Loop through the array
                for (i = 0; i < cbGroup.length; i++)
                {
                        cbGroup[i].checked = checkAllState.checked;
                }
        }
        else
        {
                // Single element so not an array
                cbGroup.checked = checkAllState.checked;
        }
}


HTML Code:
<input type=checkbox name=checkall onclick="checkUncheckAll(this, grp1);">
<input type=checkbox name=grp1 id=bx1>
<input type=checkbox name=grp1 id=bx2>
<input type=checkbox name=grp1 id=bx3>
<input type=checkbox name=grp1 id=bx4>

Strip html tags

The regex below removes html tags from string (untested).

str = <<HTML_TEXT



  

Application error

Change this error message for exceptions thrown outside of an action (like in Dispatcher setups or broken Ruby code) in public/500.html

HTML_TEXT puts str.gsub(/<\/?[^>]*>/, "")

Disable selecting text in HTML with javascript events

When you need to diable selection of text in a page use the following events in the wrapping tag. This is useful if you use javascript ondblclick and don't want the text to be selected.

onmousedown will stop the selection in Firefox. IE will still select text though so you must also use onselectstart to keep IE from selecting the text.

<td onmousedown="return false;" onselectstart="return false;">

HTML tag stripper

// *UNTESTED*
// Strips complete and incomplete HTML tags from $html

function strip_bad_tags($html)
{
   $s = preg_replace ("@]*>*@", "", $html);
   return $s;
}

ASCII-Matrix

display a matrix in ASCII-text

&#9484; -1  -1  -1 ┐
&#9474; -1  16  -1 │ * 1/8
&#9492; -1  -1  -1 ┘

Collapsable Navigation Menu

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">







Example 2










HTML META refresh

// description of your code herethe old reliable refresher.

<META HTTP-EQUIV="Refresh" CONTENT="1000;URL=/">

Selecting and checking items from HTML menus

This code allows you to pass in an HTML menu (select, radio, or checkbox) along with a single choice or an array of choices to be selected. The choice(s) should be contained literally in the value attribute.

This is handy for making persistent forms without polluting the HTML with PHP logic. For example, you could initialize all your menus to have nothing selected and then pass in GET or POST variables in case the form was not accepted, easily making form selections persistent.

/**
 * For select menus.
 */
function select_from_menu($menu,$choices,$deselect=true) {
  if ($deselect) $menu = preg_replace('/ selected(="selected")?/','',$menu);
  if(!is_array($choices)) {
    $menu = preg_replace('/(value="'.preg_quote($choices).'")/',"$1 selected=\"selected\"",$menu);
  } else foreach($choices as $value) {
    $menu = preg_replace('/(value="'.preg_quote($value).'")/',"$1 selected=\"selected\"",$menu);
  }
  
  return $menu;
}

/**
 * For radio buttons and checkboxes.
 */
function check_from_menu($menu,$choices,$deselect=true) {
  if ($deselect) $menu = preg_replace('/ checked(="checked")?/','',$menu);
  if(!is_array($choices)) {
    $menu = preg_replace('/(value="'.preg_quote($choices).'")/',"$1 checked=\"checked\"",$menu);
  } else foreach($choices as $value) {
    $menu = preg_replace('/(value="'.preg_quote($value).'")/',"$1 checked=\"checked\"",$menu);
  }

  return $menu;
}

Clear form with Javascript

Purpose: Clear all text fields in a form

Other important features:
- Resulting page must be valid XHTML 1.1
- JS must work in Firefox 1.0 and MS Internet Explorer 6.0
- JS must never generate any errors, even non-fatal ones, in the Firefox Javascript Console
- JS should only clear text input (no hidden fields or visual controls)
- Code must be readable and properly indented

Looking around the web, this was not easy to find. After a few hours of searches, and some back'n'forth at Webmaster World, I got a working version.

In XHTML header:

<script type="text/javascript" src="clear-form-input.js">script>

In html/form/div

<script type="text/javascript">
  // CDATA[
    var el = document.createElement("input");
    el.setAttribute("id", "clearButton");
    el.setAttribute("type", "button");
    el.setAttribute("value", "Clear");
    document.getElementById("deliciousFormDiv").appendChild(el);
    addEvent(el, 'click', function(){ clearForm('delicious');} );
  // ]]>
script>

In clear-form-input.js:

function clearForm(formIdent) 
{ 
  var form, elements, i, elm; 
  form = document.getElementById 
    ? document.getElementById(formIdent) 
    : document.forms[formIdent]; 

        if (document.getElementsByTagName)
        {
                elements = form.getElementsByTagName('input');
                for( i=0, elm; elm=elements.item(i++); )
                {
                        if (elm.getAttribute('type') == "text")
                        {
                                elm.value = '';
                        }
                }
        }

        // Actually looking through more elements here
        // but the result is the same.
        else
        {
                elements = form.elements;
                for( i=0, elm; elm=elements[i++]; )
                {
                        if (elm.type == "text")
                        {
                                elm.value ='';
                        }
                }
        }
}
        
function addEvent(elm, strEvent, fnHandler)
{
        return ( elm.addEventListener
        ? elm.addEventListener( strEvent, fnHandler, false)
        : elm.attachEvent( 'on'+strEvent, fnHandler)
        );
}

Redirect after 5 seconds

<HTML>
<HEAD>
  <TITLE>RedireccionadoTITLE>