JavaScript tips and tricks


javascript
Image credit:wikimedia.org

JavaScript tips and tricks

Javascript is the most widely used client side scripting language of all times. Like all programming languages, Javascript has particular positive points and hindrances. A significant number of the upsides and downsides are identified with being a client-side effectiveness.

Preferences of Javascript

Faster. Javascript is quick on the web based applications that any code of this scripting language can be run promptly as opposed to needing to contact the server and sit tight for an answer.

Effortlessness. Javascript is generally easy to learn and actualize.

Adaptability. Javascript plays pleasantly with different scripting or programming languages and can be utilized as a part of an enormous assortment of uses. Not at all like PHP or or Asp.net server side scripts, scripts, javascript can be embedded into any site page paying little mind to the platform. Javascript can likewise be utilized inside scripts composed as a part of different languages, for example, PHP, .Net, Java etc

Server Load. Being client-side lessens the load on the web server and round trips.

Now we are coming towards our main goals to show you the power of JavaScript with examples.

Reading Asp.Net server controls

Let’s begin withAsp.Net textboxes:

The control markup

<asp:TextBox id=”mytextBox” Text=”myText” runat=”server”><strong>

The javascript code

<script type=”text/javascript”>

document.getElementById(‘<%=mytextBox.ClientID%>’).value;
document.forms[0][‘mytextBox’].value;

</script>

Getting the value of imagebutton in GridView and pass the required fields as queryString to other page

function GetSelectedRow(img) {
var row = img.parentNode.parentNode;
var rowIndex = row.rowIndex – 1;
var purchaseorderID = row.cells[1].innerHTML;
var itemID = row.cells[8].innerHTML
var x = screen.width / 2 – 600 / 2;
var y = screen.height / 2 – 450 / 2;
window.open(‘UpdateTransaction.aspx?itemID=’ + itemID + ‘&purchaseorderID=’ + purchaseorderID, ‘EditWin’, ‘width=800,height=500,left=’ + x + ‘,top=’ + y);

return false;
}

Refreshing the parent when the child window is closed
function refreshParent() {
window.opener.location.href = window.opener.location.href;

if (window.opener.progressWindow)

{
window.opener.progressWindow.close()
}
window.close();
}

Make Asp.Net traditional calendar just like javascript calendar

Follow this link

Reload page after 8 seconds

loadEveryEight(function(){
window.location.reload(1);
}, 8000);

Syed Adeel Ahmed
Syed Adeel Ahmed
Analyst, Programmer, Educationist and Blogger at Technofranchise
Computer Systems Engineer from Sir Syed University Of Engineering & Technology.I am passionate about all types of programming.

Published by

Syed Adeel Ahmed

Computer Systems Engineer from Sir Syed University Of Engineering & Technology.I am passionate about all types of programming.

Leave a Reply