[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Javascript - tricks and hints



 
    
1. add tag - TARGET="_top" in your <a href ...> to let frame disapear after
   it jumps to another address:

   <a href="goaway.html" TARGET="_top"> if you don't want see my page </a>

   if you don't wanna add tag in every "ref", you can add <base target="_top">
   in the homepage head 


2. Clear your document windows:

     document.close();
     document.open();
     document.write("<P>"); 


3. Backward and forward:

   <html>
   <body>
   <FORM NAME="buttonbar">
     <INPUT TYPE="button" VALUE="Back" onClick="history.back()">
     <INPUT TYPE="button" VALUE="JS- Home" onClick="location='script.html'">
     <INPUT TYPE="button" VALUE="Next" onCLick="history.forward()">
   </FORM>
   </body>
   </html> 

   Also you can use  history.go(-1) and history.go(1) 


4. How to load two windows under one mouse click?

   frames2.html

   <HTML>
   <HEAD>
   <title>Frames</title>
   </HEAD>
     	<FRAMESET COLS="295,*"> 
   		<FRAMESET ROWS="100%,*"> 
     		<FRAME SRC="loadtwo.html" NAME="fr1"> 
       		</FRAMESET> 
   	<FRAMESET ROWS="75%,25%"> 
     		<FRAME SRC="cell.html" NAME="fr2"> 
     		<FRAME SRC="cell.html" NAME="fr3"> 
       </FRAMESET> 
   </FRAMESET> 
   </HTML>

   loadtwo.html

   <HTML>
   <HEAD>
   <script language="JavaScript">
   <!-- Hiding
   	function loadtwo(page2, page3) {
      		parent.fr2.location.href=page2;
      		parent.fr3.location.href=page3;
 	}
   // -->
   </script>
   </HEAD>
   <BODY>
   <FORM NAME="buttons">
      	<INPUT TYPE="button" VALUE="load at the same time" 
	       onClick="loadtwo('frtest1.html', 'frtest2.html')">
   </FORM>
   </BODY>
   </HTML>


5. Open a new window

   <a href="goanywhere.html" target="Resource Window">Go!</a>
				    ^^^^^^^^^^^^^^^^^

6. Verify form input is right or NOT

   <html>
   <head>
   <script language="JavaScript">
   <!-- Hide

   function test1(form) {

  	if (form.text1.value == "")
        	alert("No input, pls input again!")
  	else { 
   		alert("Hi"+form.text1.value+"! You have finished inputting!");
  	}
   }

   function test2(form) {
  
	if (form.text2.value == "" || 
      	    form.text2.value.indexOf('@', 0) == -1) 
        	alert("This is not correct e-mail address! Pls try again!");
  	else alert("Finished inputting!");
   }
   // -->
   </script>
   </head>

   <body>
   <form name="first">
   Enter your name:<br>
   <input type="text" name="text1">
   <input type="button" name="button1" value="test it..." 
          onClick="test1(this.form)">
   <P>
   Enter your e-mail address:<br>
   <input type="text" name="text2">
   <input type="button" name="button2" value="test it..." 
          onClick="test2(this.form)">
   </body> 


7. Send Email to you automatically

   <FORM METHOD=POST ACTION="mailto:terrence.miao@xxxxxxx";>
   <H3>Do you like my homepage?</H3>
   	<INPUT NAME="choice" TYPE="RADIO" VALUE="1">Not at all!#<BR>
  	<INPUT NAME="choice" TYPE="RADIO" VALUE="2" CHECKED>Waste time!#<BR>
  	<INPUT NAME="choice" TYPE="RADIO" VALUE="3">Shit all!#<BR>
  	<INPUT NAME="submit" TYPE="SUBMIT" VALUE="Send">
   </FORM>


8. Focus on...

   function setfocus() {

        document.first.text1.focus();
        return;
   }

   OR

   <body onLoad="setfocus()">

Google