Monday 1 April 2013

JavaScript alert validation on click

<!-- JavaScript alert validation on click  -->

<html>
<head>
<script type="text/javascript">
function msg()
 {
   var m = document.getElementById('textfield')
   if(m.value !="")
    {
       alert("Your Value is"+textfield.value);
     }
    else
     {
       alert("Enter some Text... ");
     }
 }
</script>
</head>
  <body>
    <input type= 'text' id= 'textfield'>
    <input type='button' onClick="msg()" value='Click Me'>
  </body>
</html>


<!-- Search box validation with JavaScript --> 


<script language="javascript" type="text/javascript">
function clearText(field)
{
    if (field.defaultValue == field.value)
 field.value = '';
    else if (field.value == '')
 field.value = field.defaultValue;
}
</script>
</head>
<body>
<div id="search_bar_wrapper">

 <div id="search_bar">
     <div id="search_box">
            <form action="#" method="get">
                <input type="text" value="Enter keyword here..." name="q" size="20" id="searchfield" title="searchfield" onfocus="clearText(this)" onblur="clearText(this)" />
                <input type="submit" name="Search" value="Search" alt="Search" id="searchbutton" title="Search" />
            </form>
        </div>
    </div>
</div>

<!-- JavaScript value split Example  -->


<html>
<head>
<script type="text/JavaScript">
function sp(){
var name,i;
name = document.getElementById("user").value;
var arraydata = name.split(',');
for(i=0;i<arraydata.length;i++){
alert(i);
//document.write(name);
a = arraydata[0];
b = arraydata[1];
c = arraydata[2];
d = arraydata[3];
}
document.writeln(a);
document.writeln(b);
document.writeln(c);
document.write(d);
return false;
}
</script>
<head>
<form name="s">
<body>
user name <input type="text" value="" name="user" id="user"/>
<input type="button" onclick ="return sp();" value="submit"/>
</body>
</form>
<html>

No comments:

Post a Comment