javascript: show/hide elements

August 13th, 2010

This little javascript function will let you show/hide elements on a form.
function showorhide(id) {
if(document.getElementById(id)){
var ele = document.getElementById(id);
if(ele.style.display==”none”){ ele.style.display=”block”; }else{ ele.style.display=”none”; [...]

Filled Under: Javascript

Javascript: check if text box exists

December 18th, 2008

How can I check in javascript if the text box control exists? Here is a simple code to check that:

var control = document.formname.elements["txt"];
var isControl = typeof control == “object”
alert(isControl);

Filled Under: Javascript

Javascript: simple way to replace a character

December 18th, 2008

Let’s say you need to replace coma (, ) to a dot (.)

Here is easiest way to do that:

test=test.split((”,”)).join(”.”);

Filled Under: Javascript

Javascript: How Do I get value from List Box

December 18th, 2008

Use this simple javascript example to get value from list box:

<script language=”javascript”>
       function test() {
            var form = document.forms[0];
            for (i=0; i < form.elements.length; i ++) {
                 if (form.elemenets[i].tagname == “select”)
                      alert(”Selected option: ” + form.elements[i].options.name);
            }
       }
</script>

Filled Under: Javascript

Javascript: how do I refresh main window and come back to main window

December 18th, 2008

This question was asked a lot: “How do I refresh main window and come back to main window using Javascript?”
Here is a loution:

opener.location.href=opener.location.href;
opener.close();

Filled Under: Javascript

Javascript: Bookmark this page

October 28th, 2008

Adding the “bookmark this page” javascript below will help to encourage return visits. Your visitor simply clicks on the link and a popup prompt will appear so they can add your site to their favorites list.

Step 1
First you place the following in your tag of your html
Change the 4th and 5th lines “var url Address [...]

Filled Under: Javascript

Javascript display current date and time

October 21st, 2008

<script>
var today=new Date()
document.write(’<center>’+today.toString()+’<br>’+window.location+’</center>’)
</script>

Filled Under: Javascript