<html>
<head>
<title>change code</title>
<script language="javascript">
function changeCode()
{
if(document.getElementById('country').selectedIndex > 6)
{
document.getElementById('ukcode').style.display="none";
document.getElementById('ukcode').style.visibility="hidden";
document.getElementById('eucode').style.display="block";
document.getElementById('eucode').style.visibility="visible";
}
else
{
document.getElementById('eucode').style.display="none";
document.getElementById('eucode').style.visibility="hidden";
document.getElementById('ukcode').style.display="block";
document.getElementById('ukcode').style.visibility="visible";
}
}
</script>
</head>
<body onLoad="changeCode();">
<table>
<tr>
<td><strong>Country:</strong></td>
<td>
<select name="country" id="country" onChange="changeCode();">
<option value="UK" selected>United Kingdom</option>
<option value="NI" >N. Ireland</option>
<option value="BF" >BFPO</option>
<option value="CI" >Channel Islands</option>
<option value="SH" >Scottish Highlands</option>
<option value="NI" >-----------</option>
<option value="E1" >Europe 1</option>
<option value="E2" >Europe 2</option>
<option value="E3" >Europe 3</option>
<option value="E4" >Europe 4</option>
</select>
</td>
</tr>
<tr>
<td colspan="2">
<div id="ukcode" name="ukcode">
<strong>Postcode (UK):</strong>
<input type="text" name="postcode1" size="3" maxlength="20">
- <input type="text" name="postcode2" size="3" maxlength="4">
</div>
</td>
</tr>
<tr>
<td colspan="2">
<div id="eucode" name="eucode">
<strong>Postcode (EU):</strong>
<input type="text" name="postcodeEU" size="8" maxlength="20">
</div>
</td>
</tr>
</table>
</body>
Showing posts with label JAVA SCRIPT. Show all posts
Showing posts with label JAVA SCRIPT. Show all posts
Text Box Characters Counter (IE, Opera, FireFox, & Safari)
In forms when using text boxes or text areas with limited character length (usually needed for forms that submit data to a database) it is always a good idea to tell the user how many characters they have remaining. This javascript snippet is especially useful for textarea fields since they can't be assigned a text limit in HTML but can be restricted using this code.
The following example shows how you can do this. This is a very simple and cute idea to help the user know exactly how many characters can be typed further. Do these small add-ons to your forms and they will look really professional. We recommend using this counter inside CMS solutions and custom built Admin Panels where your clients/visitors can be instructed to use all browsers like IE, Opera, FireFox, Netscape or Safari.
JavaScript to be pasted in head tags
<script language = "Javascript">
/**
* DHTML textbox character counter script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
*/
maxL=255;
var bName = navigator.appName;
function taLimit(taObj) {
if (taObj.value.length==maxL) return false;
return true;
}
function taCount(taObj,Cnt) {
objCnt=createObject(Cnt);
objVal=taObj.value;
if (objVal.length>maxL) objVal=objVal.substring(0,maxL);
if (objCnt) {
if(bName == "Netscape"){
objCnt.textContent=maxL-objVal.length;}
else{objCnt.innerText=maxL-objVal.length;}
}
return true;
}
function createObject(objId) {
if (document.getElementById) return document.getElementById(objId);
else if (document.layers) return eval("document." + objId);
else if (document.all) return eval("document.all." + objId);
else return eval("document." + objId);
}
</script>
html code to be pasted within body tags
<font> Maximum Number of characters for this text box is 255.<br>
<textarea onKeyPress="return taLimit(this)" onKeyUp="return taCount(this,'myCounter')" name="Description" rows=7 wrap="physical" cols=40>
</textarea>
<br><br>
You have <B><SPAN id=myCounter>255</SPAN></B> characters remaining
for your description...</font>
Print Window pop-up
This Script allows users to print the current html page.
//1. INSERT THE FOLLOWING IN THE HEAD SECTION
//2. INSERT THIS IS THE BODY SECTION
Print This Page
//1. INSERT THE FOLLOWING IN THE HEAD SECTION
//2. INSERT THIS IS THE BODY SECTION
Print This Page