Posts Tagged ‘javascript’
Get Value of Checkbox using jQuery
This one is quite an easy one, but a good one to mention non-the-less as it does definitely come in really handy. If you would like to get a checkbox’s value to send to the backend using jQuery you can always do the following: Firstly let’s draw some HTML to illustrate our example. <input id="chkOurCheckbox" type="checkbox" /> Now we need some jQuery to do the real work. var ourCheckboxValue =…
IE6 PngFix in Javascript
As a web developer you will know just how much we all love hate Internet Explorer 6 – one of the most dreaded browsers and browser versions that still exists in the deep dark corners of the interwebs – and you will probably have figured out that it doesn’t play well with PNG images. So here is how you can resolve this problem. It’s not as nice as an actual…
How many days in February?
It is quite handy to have a function that can tell you how many days there are in February due to the leap year shift of either 28 or 29 days. Below is a function created in Javascript to return the exact amount of days according to the year given: function daysInFebruary (year){ return (((year%4==0)&&((!(year%100==0))||(year%400==0)))?29:28); }
Search and Replace Anchor Href using Javascript
I have a site that is under development and it was made really badly so I needed a quick way to replace all anchors on page to the relevant path. The problem is because it was a testsite that lived away from the public facing domain, the anchors had to be changed because they were all coded in as absolute paths. I included a JavascriptDebug file and put the following…
Swap HTML Elements Using Javascript
It is quite easy to use javascript to swap between divs or any other html dom elements. Using the function below you can pass the id of the element to show and to hide. function swapDivs(show, hide){ document.getElementById(show).style.display = "block"; document.getElementById(hide).style.display = "none"; }
[Exception... "Could not convert JavaScript" nsresult: "0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)"
What the heck is.. uncaught exception: [Exception... "Could not convert JavaScript argument arg 0 [nsIDOMHTMLDivElement.appendChild]” nsresult: “0×80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)” location: “JS frame :: PATH_TO_MY_JAVASCRIPT_FILE :: THE_METHOD_NAME :: line #” data: no] For me it was just an appendChild() that was causing the problems. You can always try the innerHTML+= way if all else fails
Stop mouse click in browsers
There have been multiple ways to stop your user/s from right clicking on your site, but many of them now fail due to the way firefox’s contextual menu loads. Below is an example of how to do it: function _c(e) {if (document.all) {if (event.button==2||event.button==3) {return false;}} else {if (e.button==2||e.button==3) {e.preventDefault();e.stopPropagation();return false;}}if (e.which) {}}if (document.all){document.onmousedown=_c;}else{document.onclick=_c;document.ondblclick=_c;}</span> ..and here is the full working example in a webpage: <html> <head> <script> function _c(e) {if…
Sending data from javascript to php
If you ever find yourself needing to do some ajax and in turn sending strings of characters via javascript then you should really try encodeURIComponent() to wrap your strings in. The function escape() can also be used, but I would not recommend it as encodeURIComponent() is better, it also escapes your usual ampersand ajax limiters which solved me quite a bit of pain.
Add TinyMCE code button
I had quite a few problems adding the htmlCode button to a fairly old copy of TinyMCE (I think around version 2.x). All is resolved now and this is what I had to change: Both changes are made in “editor_template.js” file, I also swopped the 2 files so that I could include and edit editor_template.js instead of the compressed “editor_template_src.js. Using the advanced theme I added the following line near…