JavaScript – Form validation #JavaScript

The code will be helpful in validating data entry forms such as: user registration, user creati on. validate_required is used by all other functions

function validate_required(field,alerttxt)
	{
		with (field)
		{
			if (value==null||value=='')
			{
				alert(alerttxt);return false
			}
			else {return true}
		}
	}
	
	function validateTicketCreateForm(thisform)
	{
		with (thisform)
		{
			if (validate_required(type,'Type must be filled out!')==false)
			{type.focus();return false}
			
			if (validate_required(subject,'Subject must be filled out!')==false)
			{subject.focus();return false}
						
		}
	}

	function validate_customer_create_form(thisform)
	{
		with (thisform)
		{
			if (validate_required(firstName,'First name must be filled out!')==false)
			{firstName.focus();return false}
			
			if (validate_required(lastName,'Last name must be filled out!')==false)
			{lastName.focus();return false}
			
			if (validate_required(phone,'Phone must be filled out!')==false)
			{phone.focus();return false}
			
		}
	}
	
	
	function validateUserCreateForm(thisform)
	{
		with (thisform)
		{
						
			if (validate_required(firstName,'First name must be filled out!')==false)
			{firstName.focus();return false}
			
			if (validate_required(lastName,'Last name must be filled out!')==false)
			{lastName.focus();return false}
			
			if (validate_required(shortName,'Short name must be filled out!')==false)
			{shortName.focus();return false}
			
			if (validate_required(username,'Username must be filled out!')==false)
			{username.focus();return false}
			
			
			if (validate_required(password,'Password must be filled out!')==false)
			{password.focus();return false}
			
			if (password.value.length < passwordLength.value) {alert("Password must be
              at least " + passwordLength.value +" char long");
	password.focus();return false}
			
			if (validate_required(password2,'Please re-enter password!')==false)

			{password2.focus();return false}
			
			if (password.value != password2.value)
			{
				
alert("Password did not match");

				password2.focus();
				return false			
			}
			
			
		}
	}

From: http://sitestree.com/?p=3475
Categories:JavaScript
Tags:
Post Data:2016-07-09 20:36:29

Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada

JavaScript by Example #JavaScript

JavaScript by Example:

Example 1.1 A si mple JavaScript program Run View Source
Example 1.2 An HTML form with a JavaScript event handler defined Run View Source
Example 1.3 Estimating Your Taxes with JavaScript Run View Source
Example 6.1 Defining JavaScript Functions View Source
Example 6.2 Using Functions as Data View Source
Example 6.3 Checking for the Correct Number of Arguments View Source
Example 6.4 A Multi-Argument max() Function View Source
Example 6.5 Creating and Initializing an Array View Source
Example 6.6 Using Static Variables View Source
Example 7.1 A Rectangle Object Constructor Function View Source
Example 7.2 Defining and Invoking a Method View Source
Example 7.3 Defining Methods in a Constructor View Source
Example 7.4 Defining a Class with a Prototype Object View Source
Example 7.5 Defining instance/class variables and methods View Source
Example 7.6 Defining and using the valueOf() method View Source
Example 8.1 An Array Constructor View Source
Example 9.1 Copying, Passing, and Comparing by Value View Source
Example 9.2 Copying, Passing, and Comparing by Reference View Source
Example 9.3 References Themselves are Passed by Value View Source
Example 9.4 Are Strings and Functions Compared by Value or Reference? Run View Source
Example 9.5 The assign() Method View Source
Example 10.1 A Simple JavaScript Program in an HTML File Run View Source
Example 12.1 Using the alert(), confirm() and prompt() methods Run View Source
Example 12.2 Displaying and Reporting JavaScript Errors with a Run View Source
Example 12.3 Displaying a link’s destination in the status line Run View Source
Example 12.4 A digital clock in the status line Run View Source
Example 12.5 Creating an invisible frame View Source
Example 12.6 Dynamically creating and animating frames Run View Source
Example 13.1 Getting Browser Version Information View Source
Example 13.2 Extracting Arguments from a URL View Source
Example 13.3 A Navigation Bar Using the History and Location Objects View Source
Example 14.1 Creating a plain-text document Run View Source
Example 14.2 Generating XBM images with JavaScript Run View Source
Example 14.3 Listing the Links in a Document View Source
Example 14.4 A Random Hypertext Link View Source
Example 14.5 Invoking Methods of a Java applet from JavaScript View Source
Example 15.1 A Utility Class for Working with Cookies Run View Source
Example 16.1 An Animation Using Image Replacement Run View Source
Example 16.2 An Animation Using the onLoad() Event Handler Run View Source
Example 16.3 Implementing a Toggle Button with Image Replacement Run View Source
Example 17.1 An HTML Form Containing all Form Elements Run View Source
Example 17.2 Performing Form Validation Run View Source
Example 18.1 A Script Hidden from Old Browsers View Source
Example 18.2 Displaying a Message on non-JavaScript Browsers View Source
Example 18.3 Loading a JavaScript-based page only if JavaScript is supported View Source
Example 18.4 Displaying a Message with <NOSCRIPT> View Source
Example 18.5 Displaying a Message for Browsers that do not Support JavaScript 1.1 View Source
Example 18.6 A Web Page to test for JavaScript Compatibility View Source
Example 18.7 Displaying a Failure Message when using <SCRIPT SRC=> View Source
Example 19.1 Scripting the built-in Java classes Run View Source
Example 19.2 Controlling an Applet with JavaScript View Source
Example 19.3 Controlling a Plug-in from JavaScript Run View Source
Example 19.4 Using JavaScript from an Applet Method View Source
Example 19.5 A Java OutputStream for Displaying HTML in a Browser Window View Source

Reference: From: http://sitestree.com/?p=3473
Categories:JavaScript
Tags:
Post Data:2016-07-16 13:37:04

Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada

Handling Checkbox arrays with Javascript::GetElementsByName:XHTML supported #JavaScript

The following code demonstrates how to handle checkboxes with JavaScript. Note the names of all c heck boxes are same myInput[]. It could also be myInput. Both works as an array to contain the controls’ values. I prefer myInput[] as you can handle this control in PHP as an array. If you use $arr=$_POST[‘myInput’], $arr will contain the values of the controls.

Note the use of getElementsByName(). It is easy to manipulate JavaScript controls using this name. You do not need to send a value/control to the function. And in many times, document.myform.control, does not work right, specially if you want to main XHTML standard[i need to check more on this]. getElementById is also very useful. You may use getElementById for most times, but with checkbox arrays getElementsByName is better choice.

Also, note that when a form is submitted only the values of the checked check boxes are submitted to the server. You may wish to use hidden controls to keep the values, so that all values are submitted and based on the checked/non-checked you can ..control your work

<html>
	<head>
		<script type="text/javascript">
			function getElements()
			  {
			  var x=document.getElementsByName("myInput[]");
			  alert(x.length);
			  alert(x[0].value);
			  alert(x[1].value);
			  alert(x[2].value);


			  }
		</script>
</head>

<body>
	<input name="myInput[]" type="checkbox" size="20" value='10'/>10 
	<input name="myInput[]" type="checkbox" size="20" value='20' />20
	<input name="myInput[]" type="checkbox" size="20" value='30' />30

From: http://sitestree.com/?p=3471
Categories:JavaScript
Tags:
Post Data:2016-07-09 20:37:45

Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada

How to implement multiple tab webpages in Ajax and JavaScript #JavaScript

The following two examples will demonstrate how to use JavaScript and/or ajax to implement mult iple tab webpages. http://www.dynamicdrive.com/dynamicindex17/ajaxtabscontent/

http://www.barelyfitz.com/projects/tabber/example2.html

I have used the first code extensively in one of my applications. The basic ides is: you define a div section. On each click, you change the contents of that div section using Ajax concepts. You could also use Iframe and JavaScript. However, if the pages under different tabs require information from the server side then Ajax is the right choice From: http://sitestree.com/?p=3469
Categories:JavaScript
Tags:
Post Data:2016-07-10 09:38:37

Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada

Some JavaScript stuff that you need to know #JavaScript

What you really need to learn in Javascript? 
								
										

1. Where you can place JavaScript codes? 

Anywhere in the web-pages, ideally in the header section, or in an external file. If you keep 
javascript
 codes in an external file, the codes will be re-usable from different web-pages

2. Some basic programming: 
<script language="javascript" type="text/javascript">
</script> 


<script language="javascript" type="text/javascript"> 
	document.write('<b>Hello World</b>'); 
</script> 

This will only be displayed in javascript enabled browsers.

<script language="javascript" type="text/javascript"> 
	document.write('<a href="script.htm">Page Requiring Javascript</a>'); 
</script> 

3. Variables and their scopes 

<script language="javascript" type="text/javascript"> 
	var hello = 'Hello World'; 
	document.write(hello);
</script> 


var mynum = 5; 
var smokes = false; 
var riches = null; 
var today = new Date;
 
Example use of variables: 
<script language="javascript" type="text/javascript"> 
	var questions = '<p>If you have any questions about this 
 	please <a href="mailto:me@myaddress.com">email me</a>.</p>'; 
	document.write(questions);
</script> 

Another block can refer to questions variables without reassigning the value

<script language="javascript" type="text/javascript"> 
	document.write(questions);
</script> 


variables declared within a function is recognized only withing that function. Variables 
declared 
outside of a 
function is recognized anywhere in the webpage within javascript code from the declaration 
place.
 


4. Operators 

Assignment operators 

<script language="javascript" type="text/javascript"> 
	var rich = 5000; 
	var lotsOfMoney = 100000; 
	rich = lotsOfMoney; 
	document.write(rich);
</script> 

Arithmetic and concatenation operators 

five = two + three; 
profit = income - expenses; 
income = sales * price;
payment = total / instalments; 
option = randnum % choices; 
b = ++a;
c = a++;
d = --a;
e = a--; 


Combination of Operators like c/c++ 

joy += happiness; 
price -= discount; 
capital *= interest; 
pie /= slices;
options %= choice; 

Example use:


<script language="javascript" type="text/javascript"> 
	var singlePrice = 8;
	var bulkPrice = singlePrice * 9;
	document.write('<p>Buy our Widgets $'
	+singlePrice+' for one, $'+bulkPrice+' for ten</p>'); 
</script> 



5. Comparing Variables, Logical statements 

<script language="javascript" type="text/javascript"> 
	var red = 5;
	var blue = 3;
	var match = null;
	if (red == blue) 
	{
		match = 'equal'; 
	} 
	else 
	{
		match = 'unequal'; 
	}
	document.write(red + ' and ' + blue + ' are ' + match); 
</script> 


Other comparison operators: 

if (red > blue)
if (red >= blue)
if (red < blue)
if (red <= blue)
if (red != blue) 



Combining more than one comparison 

if ((red == blue) || (red == green)) 


<script language="javascript" type="text/javascript"> 
	var red = 5;
	var blue = 3;
	var green = 3;
	var match = null;
	
	if ((red == blue) && (red == green)) 
	{
		match = 'equal';
	} 
	else 
	{
		purple = 'unequal';
	}
	document.write(red + ' and ' + blue + ' are ' + match);
</script> 


Comparison in short

red == blue ? match = 'equal' : match = 'unequal'; 


instead of

if (red == blue) 
{
	match = 'equal';
} 
else 
{
      match = 'unequal'; 
}


Example Use:

<script language="javascript" type="text/javascript">
	var discPrice = 25;
	var regPrice = 25;
	var discount = regPrice - discPrice;
	if (discount > 0)
		document.write('<p>Save $'+discount+ ' off the normal price of $' +regPrice+ 'now only 
$'+discPrice+'.</p>');
	else
		document.write('<p>Buy now at our regular cheap price of $' + 
regPrice+'.</p>' ); 
</script>


6. Switch statement in Javascript, very similar to C/C++/Java

use switch instead of multiple if/else if

<script language="javascript" type="text/javascript">
	var red = 1;
	var result = null;
	switch (red) 
	{
		case 1: result = 'one'; break; 
		case 2: result = 'two'; break;
		default: result = 'unknown';
	}
	document.write(result);
</script> 


Example:

<script language="javascript" type="text/javascript"> 
	var message = 0;
	switch (message) 
	{
		case 1: document.write('Merry Christmas'); break;
		case 2: document.write('Happy New Year'); break; 
		case 3: document.write('Happy Easter'); break;
		case 4: document.write('Happy Holidays'); break;
		default: document.write('Welcome');
	}
</script> 


7. Function 
	
	
Defining a function 

function myCode() 
{
	document.write('<b>Hello World</b>'); 
} 

calling a function

myCode()

Example:

function displayMessage() 
{
	switch (message) 
	{
		case 1: document.write('Merry Christmas'); break;
		case 2: document.write('Happy New Year'); break;
		case 3: document.write('Happy Easter'); break;
		case 4: document.write('Happy Holidays'); break;
		default: document.write('Welcome');
	}
}	 


var message = 0;
displayMessage(); 


parameter passing

function writeSentence(argument1,argument2) 
{
	document.write('The '+argument1+' is '+argument2+'.<br />'); 
} 



var a = 'table';
var b = 'chair';
var c = 'red';
var d = 'blue';
writeSentence(a,c);
writeSentence(b,c);
b = 'other ' + b;
writeSentence(b,d); 
writeSentence('table',b); //passing the value directly

Example:

function displayMessage(m) 
{
	switch (m) 
	{
		case 1: document.write('Merry Christmas'); break;
		case 2: document.write('Happy New Year'); break;
		case 3: document.write('Happy Easter'); break;
		case 4: document.write('Happy Holidays'); break;
		default: document.write('Welcome');
	}
} 


In Javascript functions can also return values 

function validField(fld) 
{
	if (fld == '') return false; 
	return true;
} 


function validField(fld) 
{
	return (fld != '');
} 

How to receive returned values and process 
document.write(myField + ' is ');
if (!validField(myField)) 
{
	document.write('not '); 
}
document.write('empty'); 

8. Alert and confirm 

	
alert('Alert Message');  

Will display a message box with the message. Very useful in debugging javascript applications. 


use confirm(), when you need user agreement on an issue. like: 

if (confirm('Select a button'))
{
	alert('You selected OK'); 
}
else 
{
	alert('You selected Cancel'); 
}


9. comments 


// Scrolling Ad Javascript
// copyright 3rd September 2004, by Stephen Chapman 
// permission to use this Javascript on your web page is 
// granted provided that all of the code in this script (including 
// these comments) is used without any alteration 


or


/* Scrolling Ad Javascript
copyright 3rd September 2004, by Stephen Chapman
permission to use this Javascript on your web page is
granted provided that all of the code in this script (including
these comments) is used without any alteration */ 



10. Debugging JavaScript

    Test in different browsers like IE, Mozilla, Firfox, Netscape 
    Enable Javascript and script debugging
    Script debugging usually reside under tools menu under browsing or web development 
sub-options

    
    
    Using alert to check variable values or if you can reach to a particular point of your 
code
    
    use bookmarklets, these are small scripts that can be used as plug in into browsers to 
provide error information.
    
    
    Use firebug in firefox, also use error console under tools menu to debug javascript
 error.
    
    Visual interdev provides Javascript debugging you may also enable external debugging by 
such programs
    
    
11. External javascript


You can place all of your javascript codes to an external file. and use the file 
scripts/functions from any webpage. 
You just need to provide a reference to that external file.

You can provide reference as follows:

http://hello.js 

Note:  do not include any <script> or </script> in the external file. 


12.  Using <noscript> tag:  this tag may help you to provide some information to the
 visitors  
when javascript is disabled or not supported by the browsers.


<script language="javascript" type="text/javascript">
	document.write('<b>Hello Javascript World</b>'); 
</script>

<noscript>Hello World Without Javascript</noscript> 

<noscript>
	This page uses Javascript. Your browser either
	doesn't support Javascript or you have it turned off.
	To see this page as it is meant to appear please use
	a Javascript enabled browser.
</noscript>


13. Objects and properties in Javascript 

var strlen = myField.length; 
var str = mynum.toString(); 

function theLetter(num) 
{
	var str = 'abcdefghijklmnopqustuvwxyz';
	return str.substr(num-1,1);
}

document.write(theLetter(5)); 


14. Arrays in Javascript 

var myArray = new Array(); 

var myArray = new Array('message one',
'message two','message three'); 
document.write(myArray[0]); 
myArray[3] = 'message four'; 


function displayMessage(m) 
{
	var greeting = new Array('Welcome','Merry Christmas',
	'Happy New Year','Happy Easter','Happy Holidays');
	if (m < 0 || m > greeting.length) m = 0;
	document.write(greeting[m]); 

} 

15. Loops

for (var i=0; i<10; i++) 
{
	document.write(i);
} 


var x = 0;
while (x<10) 
{
	document.write(x); 
	x++;
} 

var x = 12;
do 
{
	document.write(x); 
	x++;
} while (x<10) 


16. Date and Time in Javascript

//current date
var myDate = new Date; 


myDate.setDate(15);
myDate.setMonth(3); // January = 0
myDate.setFullYear(2006); 

myDate.setDate(myDate.getDate()+7);

From: http://sitestree.com/?p=3467
Categories:JavaScript
Tags:
Post Data:2016-07-15 23:39:11

Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada

Installing JBOSS Tools in Eclipse #JBOSS

http://player.vimeo.com/video/39743315?portrait=0 From: http://sitestree.com/?p=2637
Categories:JBOSS
Tags:JBOSS, Tool, Eclipse
Post Data:2015-10-20 12:44:11

Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada

Configure Mac OsX for Laravel Development with Valet #Laravel

/usr/bin/ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”
brew update
brew install homebrew/php/php71
composer global require laravel/valet
export PATH=$PATH:~/.composer/vendor/bin


not required
curl -sS https://getcomposer.org/installer | php
curl https://getcomposer.org/installer | php

php -r “copy(‘https://getcomposer.org/installer’, ‘composer-setup.php’);”
php -r “if (hash_file(‘SHA384’, ‘composer-setup.php’) === ‘669656bab3166a7aff8a7506b8cb2d1c292f042046c5a994c43155c0be6190fa0355160742ab2e1c88d40d5be660b410’) { echo ‘Installer verified’; } else { echo ‘Installer corrupt’; unlink(‘composer-setup.php’); } echo PHP_EOL;”
php composer-setup.php
php -r “unlink(‘composer-setup.php’);”
pwd
ls composer.phar
sudo mv composer.phar composer
sudo mv composer /usr/bin/
composer
composer global require laravel/valet
valet install

ls .composer/
ls .composer/vendor/
ls .composer/vendor/laravel/
cd .composer/vendor/laravel/
valet install
echo $PATH
export PATH=$PATH:~/.composer/vendor/bin [should go to bash profile]
echo $PATH
valet install
cd ~/
valet install
ping foobar.dev
valet domain sayed.com
ping sayed.com
brew install mysql
brew services start mysql
sudo nano .bash_history
exit From: http://sitestree.com/?p=10679
Categories:Laravel
Tags:
Post Data:2017-06-30 19:42:07

Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada

Forge: Painless Server Management including Digital Ocean and AWS #Laravel

PAINLESS SERVER MANAGEMENT.

Sure, you can do all of these on your Own in platforms like AWS or Digital Ocean. However, Forge has made them easy and user friendly (you do not have to be an expert on Linux or so)

Numerous Cloud Providers
Choose between AWS, Digital Ocean, Linode, or even your own custom VPS. These are your servers, we just make it easy like Sunday morning.

SSL Certificate Management
Free SSL certificates

Site / Sub-Domain Management
Unlimited domain and sub-domains

Manage Queue Workers

Cron Jobs Made Simple

Load Balancing
Create and manage Nginx load balancing servers.

Horizontal Scaling

Up-To-Date Server Configuration

From: http://sitestree.com/?p=10677
Categories:Laravel
Tags:
Post Data:2017-06-30 18:43:16

Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada

Introduction to Laravel View #Laravel

[youtube https://www.youtube.com/watch?v=jqDToSwfqn8&w=640&h=360] From: http://sitestree.com/?p=10409
Categories:Laravel
Tags:
Post Data:2017-01-07 18:30:42

Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada

Laravel Localization #Laravel

[youtube https://www.youtube.com/watch?v=ad4KG_GOMgQ&w=640&h=360] From: http://sitestree.com/?p=10406
Categories:Laravel
Tags:
Post Data:2017-01-07 18:28:33

Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada