RSS feed logo RSS Feed | About Pantz.org
Miscellaneous Javascript code bits
Posted on 11-02-2002 21:13:00 EST | Updated on 11-02-2002 21:13:00 EST
Section: /software/javascript/ | Permanent Link

Below are some bits and pieces of Javascript I've collected over the years that have come in handy.

Submit a form on a timer(in milliseconds).

setTimeout('document.formname.submit()',1000);

A function that calls other functions to execute.

//if all functions return true then all systems go!
 function RunAllFunctions() {
	if(Function1() && Function2() && Function3()) {
	     return true;
     }
     else {
          return false;
     }
 }

Send browser to a certian url. Some examples.

 window.location.href = 'http://www.blah.com/warn2.shtml';
 top.location.href = 'http://www.blah.com/warn2.shtml';
 parent.location='http://www.blah.com/warn2.shtml';

Keep your javascript in file on the server.

<SCRIPT LANGUAGE="JavaScript" src="javascript/javascriptfile.js"></script>

Rename a fieldname. Good for PHP arrays submitted by a form when the form name has "[]" in the name.

//rename list items for php array
        document.formname.fieldname.name="list1[]";
        document.formname.fieldname.name="list2[]";

Keep a person from going back to a page the just came from.

window.history.forward(1);

Copy values from one frame to another.Copy from frame's name "copyFrom".Copy to frame's name "copyTo".

parent.copyTo.document.formname.fieldname.value = parent.copyFrom.document.formname.fieldname.value;
  //copy drop downs value
  if (parent.copyTo.document.formname.fieldname.options[parent.copyTo.document.formname.fieldname.selectedIndex].value == whatever){
     parent.copyFrom.document.formname.fieldname.value = "whatever"
  }

Del.icio.us! | Digg Me! | Reddit!

Related stories