Showing posts with label javascript. Show all posts
Showing posts with label javascript. Show all posts

Thursday, 3 January 2013

Close Browser Window (Tab) : JavaScript

Closing the opened tab through javaScript

Javascript:
run this

window.opener='x';
window.close();

Above example would ask for user confirmation.
Do you want to close or not ??? type


Incase you dont want confirmation from user... and force closing
Try this:

window.open('', '_self', '');
alert('Window is closing');
window.close();

Saturday, 6 October 2012

Linking CSS or JavaScrip with JSP

Linking CSS or JavaScrip with JSP

Linking StyleSheet CSS file

<link href="<s:url value="/css/style.css"/>" rel="stylesheet" type="text/css" />
{/css/style.css- this is path for css file}

 <link rel="stylesheet" type="text/css" href="styles.css">    

Linking Java Script file:

<script language="JavaScript" type="text/javascript" src="js/myFile.js"></script>

How to animate web buttons

Animate web buttons (zoom in zoom out)

Exactly not an animation. Use this javascript code to zoom in zoom out buttons on mouse hover.

--- Below is Javascript code ---



function buttonZoom(id){
      var x = Number(document.getElementById(id).width);
      for(var i=x; i<=Number(x+20); i++){
            document.getElementById(id).width = Number(i);
      }
    }
   
    function buttonZoomOut(id){
      var x = Number(document.getElementById(id).width);
      for(var i=x; i>=Number(x-20); i--){
            document.getElementById(id).width = Number(i);
      }
    }
----- Below is JSP Code ---
<embed id="button" type="image/svg+xml" src="" onclick="as();"
onmouseover="buttonZoom(this.id);" onmouseout="buttonZoomOut(this.id);" width="60"/>

Note: Specifying width in jsp embed tag is necessary

Check textbox for email format : javascript

Check textbox for email format : javascript

email format validation
check textbox for email format
check format of email id

-- Check html/ jsp textbox for email address format  --

//Use this function in javascript.
//Call the function @ textbox onChange event
function checkemail(email,errorMail)
      {          
            var testresults;
            var str=document.getElementById(email).value;
            var filter=/^.+@.+\..{2,3}$/;
            if (filter.test(str)){
                 document.getElementById(errorMail).style.display="none";
                 testresults=true;
            }
            else
            {    
                  document.getElementById(errorMail).style.display="block";
                  testresults=false;
            }
            return testresults;
}

How do I make a textbox that only accepts numbers

1. Html/ Jsp textbox which only allow numbers
2. Only numbers allowed in textbox
3. How can I use javascript to allow only numbers to be entered in a textbox
4. Allow only Numbers in a Textbox
5. Textbox number validation

//Javascript code below
function numbersOnly(myfield, e)
      {
            var key;
            var keychar;
            if (window.event)
              key = window.event.keyCode;
            else if (e)
              key = e.which;
            else
              return true;
            keychar = String.fromCharCode(key);
           
            // control keys
            if ((key==null) || (key==0) || (key==8) ||
               (key==9) || (key==13) || (key==27) )
              return true;
           
            // numbers
            else if ((("0123456789.").indexOf(keychar) > -1))
              return true;
            // decimal point jump
            else
              return false;
   }
// JSP code 

use the above javascript function @ onKeyPress event like below

<s:textfield name="textbox1" id=" textbox1" maxlength="20" onkeypress="return numbersOnly(this, event);" />
// <s:textfield> is a struts tag. Html <input> tag can also be used.