PDA

View Full Version : Helpful JavaScript for Web development



JavaScriptBank
02-04-2011, 08:24 PM
Helpful JavaScripts to develop website

JavaScript OOP with Input Display Toggle

Usage of this JavaScript code effect is just toggle (show/display) the input text fields when the users click the specified input checkboxes. But this JavaScript code example made with OOP skills, it'... detail (http://www.javascriptbank.com/javascript-oop-with-input-display-toggle.html/en//) at JavaScriptBank.com - 2.000+ free JavaScript codes (http://www.javascriptbank.com/)


http://www.javascriptbank.com/javascript.images/form/javascript-oop-with-input-display-toggle.jpg (http://www.javascriptbank.com/javascript/form/textarea/javascript-oop-with-input-display-toggle/preview/en/)
Demo: JavaScript JavaScript OOP with Input Display Toggle (http://www.javascriptbank.com/javascript-oop-with-input-display-toggle.html/en/)


How to setup

Step 1: Copy & Paste JavaScript code below in your HEAD section
JavaScript

<script type="text/javascript">
// Created by: Fang | http://www.webdeveloper.com/forum/showthread.php?p=872326#post872326
// This script downloaded from www.JavaScriptBank.com

function addElement() {
var aInput=document.getElementById('myspan').getElemen tsByTagName('input');
for(var i=0; i<aInput.length; i++) {
aInput[i].onclick=new Function('addDelete(this)');
}
}

function addDelete(obj) {
var parentSpan=document.getElementById('myspan');
if(obj.nextSibling.nodeName!='INPUT') { // add
var oInputText=document.createElement('input');
oInputText.setAttribute('type', 'text');
parentSpan.insertBefore(oInputText, obj.nextSibling);
}
else { // delete
parentSpan.removeChild(obj.nextSibling);
}
}

// Multiple onload function created by: Simon Willison
// http://simonwillison.net/2004/May/26/addLoadEvent/
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
if (oldonload) {
oldonload();
}
func();
}
}
}

addLoadEvent(function() {
addElement();
});
</script>

Step 2: Place HTML below in your BODY section
HTML

<span id="myspan">
<input type="checkbox">

<input type="checkbox">
<input type="checkbox">
</span>







JavaScript Vertical Marquee (http://www.javascriptbank.com/vertical-marquee.html) - JavaScript DHTML analog clock (http://www.javascriptbank.com/dhtml-analog-clock-ii.html/en/) - JavaScript Backwards Text (http://www.javascriptbank.com/backwards-text-2-index.html)


The Site may provide, or third parties may provide, links to non-JavaScriptBank.com Internet World Wide Web sites or resources. Because JavaScriptBank.com has no control over such sites and resources, you acknowledge and agree that JavaScriptBank.com is not responsible for the availability of such external sites or resources, and does not endorse and is not responsible or liable for any content, advertising, products, or other materials on or available from such sites or resources. You further acknowledge and agree that JavaScriptBank.com shall not be responsible or liable, directly or indirectly, for any damage or loss caused or alleged to be caused by or in connection with use of or reliance on any such content, goods or services available on or through any such site or resource.