Skip to content

Instantly share code, notes, and snippets.

@computercarguy
computercarguy / YearDay.php
Created June 26, 2012 18:00
PHP code to put a day select box and a year text box into an HTML form.
function YearInput(){
$HTMLCode = "<input type=\"text\" id=\"Year\" name=\"Year\" size=\"5\" maxlength=\"4\" value=\"Year\" onfocus=\"Focus('Year','Year')\" ";
$HTMLCode .= "onkeyup=\"NoChrs('Year')\" onblur=\"Blur('Year','Year');\" /></td>".Chr(13);
return $HTMLCode;
}
function DaySelect(){
$HTMLCode = "<select name=\"day\" id=\"day\">".Chr(13);
for ($i=1;$i<32;$i++){
$HTMLCode .= "<option value=\"".$i."\">".$i."</option>".Chr(13);
@computercarguy
computercarguy / StateSelect.php
Created June 26, 2012 17:57
PHP code to put a state or territory select box into an HTML form for North America.
function StateSelect(){
$HTMLCode = "<select id=\"State\" name=\"State\">".Chr(13);
$HTMLCode .= "<option value=\"AA\">Select...</option>".Chr(13);
$HTMLCode .= "<optgroup label=\"United States\">".Chr(13);
$HTMLCode .= "<option value=\"AL\">Alabama</option>".Chr(13);
$HTMLCode .= "<option value=\"AK\">Alaska</option>".Chr(13);
$HTMLCode .= "<option value=\"AZ\">Arizona</option>".Chr(13);
$HTMLCode .= "<option value=\"AR\">Arkansas</option>".Chr(13);
$HTMLCode .= "<option value=\"CA\">California</option>".Chr(13);
$HTMLCode .= "<option value=\"CO\">Colorado</option>".Chr(13);
@computercarguy
computercarguy / MonthSelect.php
Created June 26, 2012 17:54
PHP code to put a month select box into an HTML form
function MonthSelect(){
$HTMLCode = "<select name=\"month\" id=\"month\">".Chr(13);
$HTMLCode .= "<option value=\"01\">January</option>".Chr(13);
$HTMLCode .= "<option value=\"02\">February</option>".Chr(13);
$HTMLCode .= "<option value=\"03\">March</option>".Chr(13);
$HTMLCode .= "<option value=\"04\">April</option>".Chr(13);
$HTMLCode .= "<option value=\"05\">May</option>".Chr(13);
$HTMLCode .= "<option value=\"06\">June</option>".Chr(13);
$HTMLCode .= "<option value=\"07\">July</option>".Chr(13);
$HTMLCode .= "<option value=\"08\">August</option>".Chr(13);
@computercarguy
computercarguy / CountryCode.php
Created June 26, 2012 17:51
PHP code to put the country code select box into an HTML form
function CountrySelect(){
$HTMLCode = "<select id=\"Country\" name=\"Country\">".Chr(13);
$HTMLCode .= "<option value=\"US\">United States of America</option>".Chr(13);
$HTMLCode .= "<option value=\"AF\">Afghanistan</option>".Chr(13);
$HTMLCode .= "<option value=\"AL\">Albania</option>".Chr(13);
$HTMLCode .= "<option value=\"DZ\">Algeria</option>".Chr(13);
$HTMLCode .= "<option value=\"AS\">American Samoa</option>".Chr(13);
$HTMLCode .= "<option value=\"AD\">Andorra</option>".Chr(13);
$HTMLCode .= "<option value=\"AG\">Angola</option>".Chr(13);
$HTMLCode .= "<option value=\"AI\">Anguilla</option>".Chr(13);
@computercarguy
computercarguy / PasswordField.js
Created June 26, 2012 17:47
JavaScript to create a password field that initially has the visible word Password in the field, but then becomes an HTML password field when clicked, and reverts to the text field that says Password if left blank.
function Focus2(){
HTMLCode = "<input type=\"password\" size=\"20\" id=\"mypassword\" name=\"mypassword\" ";
HTMLCode += "onkeydown='javascript:if(event.keyCode==13){Login();}' onblur=\"Blur2()\" />";
document.getElementById("thepassword").innerHTML = HTMLCode;
document.getElementById("mypassword").focus();
document.getElementById("mypassword").focus();
}
function Blur2(){
if ((document.getElementById("mypassword").value == "") || (document.getElementById("mypassword").value == null)) {
@computercarguy
computercarguy / TextFieldFocus.js
Created June 26, 2012 17:41
JavaScript to give you the ability to put default text in a text field, then remove it when a user clicks the field, and put that text back in if they leave the field empty.
function Focus(TextboxName,TheValue){
if (document.getElementById(TextboxName).value == TheValue){
document.getElementById(TextboxName).value = "";
} }
function Blur(TextboxName,TheValue){
if (document.getElementById(TextboxName).value == ""){
document.getElementById(TextboxName).value = TheValue;
} }
@computercarguy
computercarguy / PhoneNums.js
Created June 26, 2012 17:36
JavaScript phone number validation
function FormatPhone(ThePhone){
if (ThePhone.length >= 9){
ThePhone = ThePhone.replace(/\(/gi,"");
ThePhone = ThePhone.replace(/\)/gi,"");
ThePhone = ThePhone.replace(/-/gi,"");
ThePhone = ThePhone.replace(/\ /gi,"");
return ThePhone;
} else {
return "invalid";
} }
@computercarguy
computercarguy / JS_Cookies.js
Created June 26, 2012 17:13
JavaScript Cookies
// I've had this file for a long time and it seemed like a good feature to add here
function CreateCookie(Name, Value, Days) {
// creates a cookie for web pages
// creates the cookie Name, sets the Value, and then makes it last however long the Days are
if (Days) {
NewDate = new Date();
NewDate.setTime(NewDate.getTime() + (Days * 24 * 60 * 60 * 1000));
Expires = "; expires=" + NewDate.toGMTString();
} else {