Le Kevin dot com

photographic-poetic-musical horizon

Browsing Posts tagged javascript

<input type=”image” value=”edit”> The VALUE attribute is passed by all browsers; except IE and Opera. The workaround solution is using a hidden field to pass the form action: function formAction(svalue) { var objAction = document.getElementById(“action”); objAction.value = svalue; } //Hidden Action: <input type=”hidden” name=”action” id=”action” value=””> //Submit Actions: <input type=”image” name=”submit” value=”edit” onClick=”formAction(this.value);”> <input type=”image” [...]

document.getElementByID() does not always work on cross browser, and sometime it returns null In this case, we can use document.getElementsByTagName() to loop through all the “input” and assign values Example: var Inputs = document.getElementsByTagName(“input”); for (var obj = 0; obj < Inputs.length; obj++){ var Obj = Inputs[obj]; try{ if (Obj.checked){ // some code, do something [...]

Most variables in JavaScript represent themselves internally as strings. The String class in JavaScript contains a number of handy methods, but many commonly-used functions which are available in other languages, such as the trim() function, are notably missing from JavaScript. Since strings are represented as JavaScript classes, it is possible to extend the functionality of [...]

String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, “”); }; String.prototype.replaceAll = function(item,replacewith) { var s = this; while (s.indexOf(item) >= 0) s = s.replace(item, replacewith); return s; } String.prototype.remove = function(item) { return this.replaceAll(item, “”); } function removeTags(str) { var tags = ["<B>", "<b>", "</b>", "</B>", "&nbsp;"]; for (var i in tags) str = str.remove(tags[i], “”); [...]

function copy_to_clipboard(text) { if(window.clipboardData) { window.clipboardData.setData(‘text’,text); } else { var clipboarddiv=document.getElementById(‘divclipboardswf’); if(clipboarddiv==null) { clipboarddiv=document.createElement(‘div’); clipboarddiv.setAttribute(“name”, “divclipboardswf”); clipboarddiv.setAttribute(“id”, “divclipboardswf”); document.body.appendChild(clipboarddiv); } clipboarddiv.innerHTML=’<embed src=”clipboard.swf” FlashVars=”clipboard=’+ encodeURIComponent(text)+’” width=”0″ height=”0″ type=”application/x-shockwave-flash”></embed>’; } alert(‘The text is copied to your clipboard…’); return false; } http://www.webtips.co.in/postimg/clipboard.rar via: http://www.webtips.co.in/javascript/copy-to-clipboard-with-javascript-on-mozilla-firefox-and-ie.aspx also: http://code.google.com/p/zeroclipboard/