Select All Text In Element on Click (JavaScript OR jQuery)
To select all text inside an element such as DIV, we can simply use JavaScript document.createRange() method to create a range, and than using range.selectNodeContents() we can set node range (start and end), after which use selection.addRange() to select the range of the element.
Select Box Change Dependent Options dynamically (JavaScript Object)
There are different solutions you can find that shows how to change/load the content in child <SELECT> element, depending on the selection of the parent <SELECT> options. Most examples uses Ajax or page refresh methods to achieve, which of-course are useful depending on the circumstance. But if you wish to use another simple method using pure JavaScript, here’s how you can do it.
Adding Markers onClick in Google Map v3
If you are wondering how to add markers on Google Map, here’s the simple Javascript snippet that adds dragable marker on Google Map. Just click on Drop Marker button to drop marker on the Map.
Redirect users to a new Page
There are various methods we can use to redirect users to different URL. Let’s have a look at codes below with just one goal.
HTML Meta Refresh Tag
Most common way to redirect users to another location is using HTML refresh meta tag, just have this code placed within the <head></head> section of your HTML page :
Javascript Location
And here is another method using Javascript window.location, only downside is if browser doesn’t support Javascript, this code will fail to redirect user to new location:
//Will take you to sanwebe.com
window.location.href = 'http://www.sanwebe.com';
PHP Header
We can use PHP header to redirect user to new URL easily, but remember there must be NO other output before this code, such as echo code which will trigger “headers already sent” error.
Perl Location
Here’s perl code to redirect user to sanwebe.com.
#!/usr/bin/perl
$url = "https://www.sanwebe.com/";
print "Location: $url\n\n";