Archive for the ‘Designing’ Category

Date Function in Javascript

1.create a date object and store it in a variable

var d= new Date();

 

2.Using the date object,Get the hour,minute,second,month,dayofmonth and year of the Current Date

var hour        = d.getHours();
var minute      = d.getMinutes();
var second      = d.getSeconds();
var month = d.getMonth();
var dayofmonth    = d.getDate();
var year        = d.getYear();

Example:-
Display Next Day of Today

function getNextDate()
{
var date= new Date();
var day = date.getDate();
var month = date.getMonth();
var year = date.getYear();
 
var nextdate= new Date(year, month, day +1);
var nxtDate=nextdate.getMonth()+1+"/"+nextdate.getDate()+"/"+NextDate.getYear();
document.getElementById('DisplaynextDate').value=nxtDate;
//Display Next Date(today+1)
}

Popularity: 1% [?]

Disable Right Mouse Click Using JavaScript

Description:
This script will prevent the default right menu from popping up when the right mouse is clicked on the web page. Works well in IE4+ and NS4+.

To use this script, paste the following code in the <body> section of your HTML document.
 

Disable right click on mouse

 

Function to handle right click if the browser is IE

<script language="JavaScript">
var message=”Right Click is Disabled”;
function ExeForIE()
{
  if (event.button==2)
  {
     alert(message);
     return false;
  }
}
</script>

 

Function to handle right click if the browser is FireFox

<script language=JavaScript>
var message=”Right Click is Disabled”;
function ExeForFFox(evt)
{
  if (document.layersdocument.getElementById&&!document.all )
  {
    if (evt.which==2evt.which==3)
    {
      alert(message);
      return false;
    }
  }
}
 
if (document.layers)
{
  document.captureEvents(Event.MOUSEDOWN);
  document.onmousedown = ExeForFFox;
}
else if (document.all&amp;&amp;!document.getElementById)
{
  document.onmousedown = ExeForIE;
}
document.oncontextmenu=new Function(alert(message);return false)
</script>

Popularity: 4% [?]

Block JavaScript Errors

We can have a function with return true and use it on window.onerror.Thus when the browser encounters a JavaScript error it returns true and block the error begin displayed.

function blkError()
{
  return true;
}
window.onerror = blkError;

Popularity: 1% [?]

Add a Row Dynamically using JavaScript

How to Add a Row Dynamically Using JavaScript:

  • We can see how button,textbox,textarea can be added Dynamically
  • All the tag which can be given in the input tag has to be given in setAttribute as shown in below coding
  • if u call a function then call as but1.onclick = function () {show(this)};
  • If u delete the Row,then reorder all the other row

1.If u Add a Button to a Table,then use this

var cell1 = row.insertCell(0);
but1 = document.createElement('input');
but1.setAttribute('type', 'button');
but1.setAttribute('className', 'button');
but1.setAttribute('value', '');
but1.onclick = function () {show(this)};
cell1.appendChild(but1);

2.If u Add a Textbox to a Table,then use this

 
var cell2 = row.insertCell(1);
var txt = document.createElement('input');
txt.setAttribute('type', 'text');
txt.setAttribute('name', 'firsttextbox');
txt.setAttribute('className', 'text_box');
txt.setAttribute('id', 'firsttextbox' + iteration);
txt.setAttribute('size', '21');
cell2.appendChild(txt);

3.If u Add a Textarea to a Table,then use this

cell1 = row.insertCell(1);
var e1 = document.createElement('textarea');
e1.name = 'text2' + iteration;
e1.id = 'text2' + iteration;
e1.column= '50';
cell1.appendChild(e1);

4.Row can be Re-Order by using

var tbl = delRow.parentNode.parentNode;
tbl.tBodies[0].rows[i].myRow.two.id = 'firsttextbox' + count;

If u Delete 3 Row the Reorder as
4th Row as—-3th Row
5th Row as—-4th Row
6th Row as—-5th Row

5.If u want to Delete the Third Row,then use this coding

 
var delRow = obj.parentNode.parentNode;
var rowArray = new Array(delRow);
for (var i=0; i&lt;rowObjArray.length; i++)</div>
{
  var rIndex = rowObjArray[i].sectionRowIndex;
  rowObjArray[i].parentNode.deleteRow(rIndex);
}
  • We have to pass all the id in the row as deleterow(this)
  • this can be get in the obj variable
  • Using the For Loop we have to Delete the Particular Row

Demo Link

Popularity: 4% [?]

Javascript compare two numbers

How to compare two Value in JavaScipts:

1.Get the Value From Html Page using getElementById

2.Compare by Using parseInt For Interger Value and parseFloat For Float Value

3.compare two value as

var first=document.getElementById('first').value;
var second=document.getElementById('second').value; 
 
if(parseInt(first)&lt;parseInt(second))
alert('Second Value is Greater than first');
 
else if(parseInt(first)&gt;parseInt(second))
alert('First Value is Greater than second');
 
else if(parseInt(first)==parseInt(second))
alert('First Value and second value is equal');

4.Include the code in Html Page For TextBox

First Value:<input type="text" value="0" onkeyup="compare();" name="first" id="first">
Second Value:<input type="text" value="0" onkeyup="compare();" name="second" id="second">

Demo Link

Popularity: 41% [?]

JavaScript to Validate Email Format

To validate the email format,  check the textbox value across the regular expression value. The javascript code and corresponding html code are:

Script :

var efmt=/^\w+((-\w+)(\.\w+))*\@[A-Za-z0-9]+((\.-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;  
 
function checkEmailFormat(field,msg)
{
  var ctrl=document.getElementById(field);
  if((!efmt.test(ctrl.value)) &amp;&amp; ctrl.value!=)
  {
    alert(msg);
    ctrl.focus();
  }
}

Add the following code into the Body tag.
Html Code :

<input type=”Text” onblur=”checkEmailFormat(’Txtemail’,'Please enter a valid email address, like sample@yahoo.com’);” id=”Txtemail” >; 

Demo Link

Popularity: 6% [?]

How to Embed a Flash File into C# Window Form?

To embed a flash file in C# Windows .Net Application we can use Shockwave Flash Object ActiveX Control.

Follow the Steps to embed flash file:

Step 1: In Tool box right click and select the menu “Choose Items”.

Step 2: From Choose Toolbox Items window select “Com component” tab.

Step 3: Scroll down and make sure “Shockwave Flash Object” is ticked and click ok. The Shockwave Flash Object will now appear in the toolbox.

Step 4: Simply click and drag the Shockwave Flash Object to window Form.

Step 5: Add the Code “Form Load”.

axShockwaveFlash1.LoadMovie(0, Application.StartupPath + “flash.swf”);

These steps embed the flash file and loads “flash.swf” in the application path when window loads.

Popularity: 14% [?]

set focus on textbox value at the end

To set focus on textbox Value at the End using javascript follow the steps:

1.Assuming ‘Search’ is the id given for the Textbox.
2.setFocus() function called on BODY load.
3.The function will position the cursor at the end of the Textbox value
(if any value Present it will point at the end of the value)

function setFocus()
{
var field = document.form.Search;
field.focus();
field.value = field.value;
field.focus();
}

 

Demo Link

Popularity: 1% [?]

Refresh the Window

To refresh the window using JavaScript

window.location.reload();

 

Popularity: 1% [?]

Set textbox background color when clicked

To set the background color of the textbox, use the ‘backgroundColor’ property.
eg.

<input type="text" style='background:#fce09a' value='www.fordevs.com'>

If you want to set the background color on text focus then use the ‘onfocus’ event.

The following example illustrates you how to set the color in ‘onfocus’ event. When the texbox loses the focus then normal background color is retained.

<html>
<body>
<br><input class="searchInput" id="searchtextbox" onblur="this.style.backgroundColor='#ffffff';"
onfocus="this.style.backgroundColor='#fce09a';value=''" accesskey="s" value="[Enter your name]" name="searchtextbox" autocomplete="off"> <br>
<br>
</html>

Demo link

Popularity: 7% [?]

Designed by: Business Web Hosting | Thanks to Buy Icons, travel tips and Used Cars