Category Archives: JavaScript

How to find your Google Plus ID

This is so simple

1. Go to your Google + account (https://plus.google.com/).

2. Click on the Profile icon on the Left.

3. If you look at the URL in the address bar, it should look something like this:

https://plus.google.com/104653270154306099169/posts

4. The long numerical string in the URL is your Google+ ID. Here is CoderzHeaven’s from the URL above:

104653270154306099169/

Google + CoderzHeaven

How to Refresh a HTML Page Using JavaScript ?

Hi,

Most probably you may have encountered a situation where you have to refresh the web page in your code.
Here is, how it could be done using JavaScript.











Here on button click it will call the function ‘refresh_yourPage()’, and it will refresh the page!

:)

Passing a Value to a Function in JavaScript – An Example

Hi,

Given below, is an example for passing a value to a function in JavaScript.

<html>
<head>
<title>Passing A Value To A Function</title>
<script language="JavaScript">
<!--
function yourFunc(urVal)
{
    alert(urVal);
}
//  -->
</script>
</head>
<body>
<P>Click <input type="button" value="this" onClick="yourFunc('CoderzHeaven')"> button for passing value!</p>
<br>
</body>
</html>

Converting String to Upper Case in JavaScript

Hi,

For converting a string to upper case in javascript, use the following code.


<html>
<head>
<title>Convert String</title>
<script type="text/javascript" language="javascript">
<!-- //
onload = function(){
    var str = new String("coderzheaven");
    var toUpperCase = str.toUpperCase();
    document.write(toUpperCase);
}
// -->
</script>
</head>
<body>

</body>
</html>

It will give you ‘CODERZHEAVEN’

:)

How to place a label or textBox or anyother control inside a tableView in Titanium, ANDROID or iPhone ?

Hi all……..
This tutorial is for Titanium users. This tutorial explains how to place a textBox or anyother control inside a tableView.
A tableview requires data in the form of a array, so we create an array (here array is named “data_array“) by adding the controls like textboxes and labels inside it. You can give a large number of properties to customize the controls. i have given some of them.

                var data_array= [];  // This is the array that we are going to give to the tableView.

                /* creating a textField to place in the tableView */
                var name_tf = Titanium.UI.createTextField({
			color:'#336699',
			hintText: 'Enter Name',
			height:45,
			value: "",
			left:100,right:10,
			textAlign:'right',
			autocorrect:false,
			scrollable:false,
			clearButtonMode:Titanium.UI.INPUT_BUTTONMODE_ONFOCUS,
			borderStyle:Titanium.UI.INPUT_BORDERSTYLE_NONE
		});

               var place_tf = Titanium.UI.createTextField({
			color:'#336699',
			hintText: 'Enter place',
			height:45,
			value: "",
			left:100,right:10,
			textAlign:'right',
			autocorrect:false,
			scrollable:false,
			clearButtonMode:Titanium.UI.INPUT_BUTTONMODE_ONFOCUS,
			borderStyle:Titanium.UI.INPUT_BORDERSTYLE_NONE
		});

              function addFirstRow()
		{
			var row = Ti.UI.createTableViewRow({height:45});
			row.backgroundColor = '#ffffff';
			row.selectedBackgroundColor = '#ffffff';

                        /* creating a label to place in the tableView */
			var label = Titanium.UI.createLabel({
					color:'#000', height:45,left:10,text:'App Name', width:280,
					font:{fontSize:18,fontFamily:'Arial', fontWeight:'bold'}
			});

			row.add(label);
			row.add(name_tf );
			row.selectionStyle = Ti.UI.iPhone.TableViewCellSelectionStyle.NONE;
			row.className = 'control';
			data_array[0] = row;
		}

               function addSecondRow()
		{
			var row = Ti.UI.createTableViewRow({height:45});
			row.backgroundColor = '#ffffff';
			row.selectedBackgroundColor = '#ffffff';

			var label = Titanium.UI.createLabel({
					color:'#000', height:45,left:10,text:'App Name', width:280,
					font:{fontSize:18,fontFamily:'Arial', fontWeight:'bold'}
			});

			row.add(label);
			row.add(place_tf );
			row.selectionStyle = Ti.UI.iPhone.TableViewCellSelectionStyle.NONE;
			row.className = 'control';
			data_array[1] = row;
		}

                addFirstRow();    /* calling the above functions */
                addSecondRow();

              /* Creating a tableView and placing the TextBox and Label inside it
                  here data is the property for which we have to provide the data-source */

               var tableview = Titanium.UI.createTableView({
			data:data_array,
			height:260,
			width:320,
			backgroundColor:'transparent',
			scrollable:'false',
			style:Titanium.UI.iPhone.TableViewStyle.GROUPED,
			top:25
		});

Now you have created a tableView with 2 controls in each row.
Make sure to add this to your window to view it.
Please leave your comments if this post was useful.

How to load a PDF in Titanium?

Loading a PDF file in Titanium may be sometimes our requirement for an application. For loading a PDF we need to have a webview inside a scrollview so that it is scrollable also. Take a look at this simple example.

/** creating a window **/
var window = Titanium.UI.createWindow{};
/** creating a webview **/
var my_webview = Titanium.UI.createWebView({     url :'my_pdf.pdf'      //specify the PDF path.....});
/** creating a scrollview **/var my_scrollView = Titanium.UI.createScrollableView({     views:[my_webview]   // placing the webview inside the scrollview...});
window.add(scrollView);

Please leave your valuable comments if this post was useful…..

Client Side Form Validation – using JavaScript

Hi, JavaScript is mainly used for client side scripting. In client side scripting one of the thing which we are usually in need is Validation of Forms. We want to know the user , who is interacting with the form have already given the necessary details before submitting or saving etc. Here is a simple form validation example using JavaScript where the form is checked for a particular text field have entered or not. Here is the form code

First name:

It contains a Text field to enter first name and a button to save.
On clicking the Save button it will go for ‘validateForm()’ function and checks for user entry.

validateForm() code

[/css]
function validateForm()
{
var x=document.forms["trialForm"]["firstName"].value
if (x==null || x=="")
  {
  alert("Enter your first name before saving!");
  return false;
  }
}

This function checks for it & returns alert if it is not filled properly! :)

Using Arrays in JavaScript – Basics

Hi…

We all know, Arrays are nothing but variables which can hold all your variable values with a single name.

Let’s see some basic operations of Arrays in JavaScript.

To Create a New Array. Use the following code.

 var myArray = new Array();

This code of line created a new Array object called myArray.

Adding Elements to myArray

myArray[0]= "you";
myArray[1] = "me";
myArray[2] = "we";

or

var myArray=new Array("you","me","we"); 

or

var myArray=["you","me","we"];

Accessing Array Elements

document.write(myArray[0]);

It will print ‘you’!

:)

Hide and Show a Text Using jQuery – Example

With jQuery manipulation of HTML & CSS can be done very easily.
Here we are going to show how to Hide a line of text using jQuery & Show it back also.
Let’s code speak first….


<html>
<head>

<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">

$(document).ready(function(){
$("#hideButton").click(function(){
$("p").hide();
});

$("#showButton").click(function(){
$("p").show();
});
});
</script>

</head>
<body>

<p>Hey! Click 'Left', I will vanish! Click 'Right', I will be back!</p>

<button id="hideButton">Left</button>
<button id="showButton">Right</button>
</body>
</html>

Note : Download and put ‘jquery.js’ on your working folder before trying out!

What these code did?

Here we have one line text, html paragraph. Two buttons ‘Left’ & ‘RIght’ and whose id’s

are ‘hideButton’ & ‘showButton’ respectively.

jQuery code identifies which button we clicked using the button id’s mentioned above and

apply the hide() or show() function to the html paragraph p.

:)