Showing posts with label creating. Show all posts
Showing posts with label creating. Show all posts

Thursday, February 5, 2015

Creating EasyTooltip class Part 21

In this tutorial well work on removing listeners and tooltips.

First of all, go to TooltipListener class and update the kill() function. Right now it only removes the 2 mouse event listeners. It should also stop the timer, remove its listener, set it to null and set the tooltip to null.

public function kill():void {
list.removeEventListener(MouseEvent.ROLL_OVER, onOver);
list.removeEventListener(MouseEvent.ROLL_OUT, onOut);
timer.removeEventListener(TimerEvent.TIMER_COMPLETE, onTimer);
timer.stop();
timer = null;
tip = null;
}

Full TooltipListener class:

package com.kircode.EasyTooltip 
{
import flash.display.DisplayObject;
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.utils.Timer;

/**
* Manages a single visible object that displays a tooltip when rolled over.
* @author Kirill Poletaev
*/
public class TooltipListener
{

public var tip:Tooltip;
public var list:DisplayObject;
private var timer:Timer;

public function TooltipListener(listener:DisplayObject, tooltip:Tooltip, delay:int)
{
list = listener;
tip = tooltip;
timer = new Timer(delay, 1);
timer.addEventListener(TimerEvent.TIMER_COMPLETE, onTimer);
listener.addEventListener(MouseEvent.ROLL_OVER, onOver);
listener.addEventListener(MouseEvent.ROLL_OUT, onOut);
}

public function kill():void {
list.removeEventListener(MouseEvent.ROLL_OVER, onOver);
list.removeEventListener(MouseEvent.ROLL_OUT, onOut);
timer.removeEventListener(TimerEvent.TIMER_COMPLETE, onTimer);
timer.stop();
timer = null;
tip = null;
}

private function onOver(evt:MouseEvent):void {
timer.reset();
timer.start();
}

private function onOut(evt:MouseEvent):void {
tip.display = false;
timer.stop();
}

private function onTimer(evt:TimerEvent):void {
tip.display = true;
}

}

}

Now go to EasyTooltip class and add a function called removeListener(). Give it a parameter "listener", which is the DisplayObject instance that has a tooltip listener. In the function, we loop through the listeners and compare each "list" property of the listener in the array to the listener in the parameter. If they match, remove that listener using kill() method of the TooltipListener instance, set it to null, and remove the item from the array.

/**
* Removes a Tooltip listener.
* @paramlistener The object that invokes tooltip on roll over.
*/

public function removeListener(listener:DisplayObject):void {
for (var i:int = listeners.length-1; i >= 0; i--) {
if (listener == listeners[i].list) {
listeners[i].kill();
listeners[i] = null;
listeners.splice(i, 1);
}
}
}

Add a new function called kill(), which loops through the listeners and kills each one. Then remove the TooltipCursor, the ENTER_FRAME listener and set the cursor to null.

/**
* Completely removes the EasyTooltip manager, all the listeners and tooltip cursor.
*/

public function kill():void {
for (var i:int = listeners.length-1; i >= 0; i--) {
listeners[i].kill();
listeners[i] = null;
listeners.splice(i, 1);
}
(par as DisplayObjectContainer).removeChild(cursor);
cursor.removeEventListener(Event.ENTER_FRAME, onFrame);
cursor = null;
}

Full EasyTooltip code:

package com.kircode.EasyTooltip 
{
import flash.display.DisplayObjectContainer;
import flash.display.DisplayObject;
import flash.events.Event;
/**
* Utility for creation of tooltips.
* @author Kirill Poletaev
*/
public class EasyTooltip
{

private var par:DisplayObject;
public var listeners:Array;
private var cursor:TooltipCursor;
private var parW:int;
private var parH:int;
private var delay:int;
private var smooth:Number;

/**
* Create a Tooltip manager. Needed for creating and managing tooltips.
* @paramparent Reference to the parent of tooltips - the container, which will contain the objects that will be rolled over.
* @paramparentWidth Width of the parent.
* @paramparentHeight Height of the parent.
* @paramsmoothMovement The movement smoothener - the bigger the value, the smoother the movement. 1 = no smoothment.
* @paramspawnDelay Delay in milliseconds of how long the user has to hold their mouse over the object to invoke a tooltip.
*/

public function EasyTooltip(parent:DisplayObjectContainer, parentWidth:int, parentHeight:int, smoothMovement:Number = 3, spawnDelay:int = 0)
{
smooth = smoothMovement;
delay = spawnDelay;
par = parent;
listeners = [];
parW = parentWidth;
parH = parentHeight;
cursor = new TooltipCursor(parentWidth, parentHeight, smoothMovement);
cursor.mouseChildren = false;
cursor.mouseEnabled = false;
parent.addChild(cursor);
cursor.addEventListener(Event.ENTER_FRAME, onFrame);
setStyle(new TooltipStyle());
trace("Tooltip manager created!");
}

/**
* Set a new style for the tooltips.
* @paramstyle TooltipStyle object that defines the style.
*/

public function setStyle(style:TooltipStyle):void {
cursor.setStyle(style);
}

/**
* Add a Tooltip listener.
* @paramlistener Object, which invokes the tooltip on roll over.
* @paramtooltip Message to be displayed.
* @returnNewly created Tooltip object. Can be used to dynamically change its properties in real-time.
*/

public function addListener(listener:DisplayObject, tooltip:String):Tooltip {
var tip:Tooltip = new Tooltip(tooltip);
var list:TooltipListener = new TooltipListener(listener, tip, delay);
listeners.push(list);
return tip;
}

/**
* Removes a Tooltip listener.
* @paramlistener The object that invokes tooltip on roll over.
*/

public function removeListener(listener:DisplayObject):void {
for (var i:int = listeners.length-1; i >= 0; i--) {
if (listener == listeners[i].list) {
listeners[i].kill();
listeners[i] = null;
listeners.splice(i, 1);
}
}
}

/**
* Completely removes the EasyTooltip manager, all the listeners and tooltip cursor.
*/

public function kill():void {
for (var i:int = listeners.length-1; i >= 0; i--) {
listeners[i].kill();
listeners[i] = null;
listeners.splice(i, 1);
}
(par as DisplayObjectContainer).removeChild(cursor);
cursor.removeEventListener(Event.ENTER_FRAME, onFrame);
cursor = null;
}

private function onFrame(evt:Event):void {
cursor.x += (par.mouseX - cursor.x)/smooth;
cursor.y += (par.mouseY - cursor.y)/smooth;
var displayInd:int = -1;
for (var i:int = 0; i < listeners.length; i++) {
if (listeners[i].tip.display) {
displayInd = i;
break;
}
}
if (displayInd == -1) {
cursor.alpha = 0;
}else {
cursor.alpha = 1;
cursor.setText(listeners[displayInd].tip.msg);
}
}

}

}

Thats all for today.

Thanks for reading!
Read more »

Creating a Simple Animated Button Flash Tutorial

This article comes with exercise files. Click on the link below to download:
[GO TO EXERCISE FILES DOWNLOAD PAGE]

Step 1
Open the animated-button.fla file. On the Stage, you will see a smiley face.

Step 2
Use your selection tool to select the smiley face on the stage. MAKE SURE YOU SELECT THE WHOLE ARTWORK. Dont just click on it. Instead, use the selection tool to click and drag a selection area around the smiley face to ensure that the whole drawing is selected.

Then convert it into a button symbol named ButtonSmiley.

Step 3
Now double-click on the ButtonSmiley instance on the stage in order to enter symbol editing mode. In the edit bar, you should now see that you are inside the ButtonSmiley timeline.

Step 4
You will see that the UP state already has a keyframe. Insert keyframes in the OVER, DOWN, and HIT states as well.

Step 5
Then click on the OVER keyframe in order to select it. This is where we will place the animation so that the button becomes animated whenever the user mouses over it. The animation will actually be nested inside a movie clip thats going to be inside this OVER keyframe. Well learn how to do that in the steps that follow.

Step 6
Once the OVER keyframe is selected, go to the stage and make sure that the smiley face is selected. MAKE SURE THAT THE ENTIRE THING IS SELECTED. Then convert it into a movie clip symbol named SmileyAnimation. We are converting it into a movie clip symbol so that we can place the animation inside it.

Step 7
After converting it into a symbol, double-click on the SmileyAnimation instance on the stage in order go inside its timeline. In the edit bar, you should see that you are now inside the timeline of the SmileyAnimation movie clip.

And remember, this movie clip instance is inside the OVER keyframe of the ButtonSmiley symbol.

Step 8
To animate the smiley face, we can use classic tweens. But first, well need to convert the smiley face into a symbol again since we are now actually inside the timeline of the SmileyAnimation movie clip. Inside the SmileyAnimation movie clip, the smiley face on the stage is just a drawing. Its not yet a symbol. Well need to convert into a symbol so that we can use classic tweens to animate it. So once again, make sure that the whole smiley face is selected and convert it into a movie clip symbol. This time, just name it Smiley.

So now, we have the Smiley symbol, which is inside the SmileyAnimation symbol, which is inside the OVER keyframe of the ButtonSmiley symbol.

Step 9
Then insert keyframes on frames 10 and 20 of the SmileyAnimation symbols timeline.

Step 10
Then go back to the keyframe on frame 10.

Step 11
Once you are back on the keyframe on frame 10, increase the size of the instance of the Smiley symbol on the stage. Select the free transform tool to be able to scale the instance on the stage.

Once the free transform tool is selected, click on the Smiley instance on the stage to make sure that its selected. DO NOT DOUBLE CLICK IT. Just click it once.

You should then see adjustment handles on the corners and the sides of the instance.

Place the cursor over any of the corner handles and click and drag outward in order to make the Smiley instance bigger.

Step 12
Once youve increased the size, insert classic tweens in between all of the keyframes. We have 3 keyframes, so well insert a classic tween between the first and middle keyframes, and then well insert another one between the middle and last keyframes. To insert a classic tween, right-click anywhere in between the keyframes and choose Create Classic Tween.

Once the classic tweens have been added, your animation should now be complete.

To recap, youve created a nested animation inside the SmileyAnimation symbol. And since the SmileyAnimation symbol is inside the OVER keyframe of the ButtonSmiley symbol, this means that the animation is only going to come out when the user mouses over the button.

Step 13
Test the movie by pressing ctrl + enter (PC) or cmd + return (Mac). Once the test movie comes out, mouse over the smiley face and watch it animate. When you mouse out of the button, then the animation will stop. Mouse over it again, and the animation starts again.

Congratulations! You have just created an animated button.
Read more »

Creating a Pentomino game using AS3 Part 17

Today well add the ability to draw holes and cells on the grid.

First of all well declare 3 new variables, 2 of which are booleans set to false by default, and third is a Point variable with default coordinates -1;-1.

private var canDraw:Boolean = false;
private var mouseDown:Boolean = false;
private var currentCell:Point = new Point(-1, -1);

In the constructor, add 3 new event listeners for MOUSE_DOWN, MOUSE_UP and ENTER_FRAME events:

addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
addEventListener(Event.ENTER_FRAME, onEnterFrame);

The canDraw value will be off when the canvas size window is open, and on when the window is closed. Thats why we can set canDraw to false in the beginning of newLevel() and to true in the end of its editContinue() function:

private function newLevel():void {
canDraw = false;

var newScreen:MovieClip = new new_edit_screen();
addChild(newScreen);
newScreen.tWidth.restrict = "0-9";
newScreen.tHeight.restrict = "0-9";
newScreen.tWidth.text = 10;
newScreen.tHeight.text = 6;
newScreen.incorrect.alpha = 0;
newScreen.btn_continue.addEventListener(MouseEvent.CLICK, editContinue);

function editContinue(evt:MouseEvent):void {
if (newScreen.tWidth.text == "" || newScreen.tHeight.text == "" || newScreen.tWidth.text == "0" || newScreen.tHeight.text == "0") {
newScreen.incorrect.alpha = 1;
return;
}
newScreen.parent.removeChild(newScreen);
mapGrid = [];
var width:int = newScreen.tWidth.text;
var height:int = newScreen.tHeight.text;
for (var i:int = 0; i < height; i++) {
mapGrid[i] = [];
for (var u:int = 0; u < width; u++) {
mapGrid[i][u] = 1;
}
}
// grid settings
calculateGrid();
gridShape.x = gridStartX;
gridShape.y = gridStartY;

// draw tiles
drawGrid();

// canPutShape settings
canPutShape.graphics.clear();
canPutShape.graphics.lineStyle(2, 0xff0000);
canPutShape.graphics.drawRect(0, 0, gridCellWidth, gridCellWidth);
canPutShape.alpha = 0;

canDraw = true;
}
}

The mouseDown value is set to true in onMouseDown() and to false in onMouseUp(). Moreover, we set currentCell to -1;-1 point in onMouseUp():

private function onMouseDown(evt:MouseEvent):void {
mouseDown = true;
}

private function onMouseUp(evt:MouseEvent):void {
mouseDown = false;
currentCell = new Point(-1, -1)
}

Were using the currentCell variable because our drawing tool will be similar to a brush, but it also has to toggle cells (from a hole to a cell, and from a cell to a hole). If the user once clicked on a cell, it toggles its value. But since we are going to have our drawing code written in an ENTER_FRAME event handler, we need to make sure the same cell doesnt get toggled more than once.

In the onEnterFrame() function, we check if we are allowed to draw and if the mouse is held down. Then we check if the users mouse is rolled over a cell. If it is, we check if that cell does not have the coordinates of currentCell. And if so, we toggle the value, set currentCells coordinates to currently selected cells coordinates and call drawGrid():

private function onEnterFrame(evt:Event):void {
// if drawing is allowed and mouse is down
if (canDraw && mouseDown) {
var mousePos:Point = new Point(Math.floor((mouseX - gridStartX) / gridCellWidth), Math.floor((mouseY - gridStartY) / gridCellWidth));
// if valid coordinates
if (mousePos.x < mapGrid[0].length && mousePos.y < mapGrid.length && mousePos.x >= 0 && mousePos.y >= 0) {
// if the cell is not "current cell"
if (mousePos.x != currentCell.x || mousePos.y != currentCell.y) {
currentCell.x = mousePos.x;
currentCell.y = mousePos.y;
if (mapGrid[mousePos.y][mousePos.x] == 1) {
mapGrid[mousePos.y][mousePos.x] = 0;
}else {
mapGrid[mousePos.y][mousePos.x] = 1;
}
drawGrid();
}
}
}
}

Full code so far:

package  
{
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.events.MouseEvent;
import flash.geom.Point;
import flash.sampler.NewObjectSample;
import flash.utils.ByteArray;

/**
* Open-source pentomino game engine
* @author Kirill Poletaev
*/

public class pentomino_editor extends MovieClip
{
private var mapGrid:Array = [];
private var shapeButtons:Array = [];

private var gridShape:Sprite = new Sprite();
private var canPutShape:Sprite = new Sprite();
private var gridStartX:int;
private var gridStartY:int;
private var gridCellWidth:int;
private var canDraw:Boolean = false;
private var mouseDown:Boolean = false;
private var currentCell:Point = new Point(-1, -1);

public function pentomino_editor()
{
addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
addEventListener(Event.ENTER_FRAME, onEnterFrame);

// add shape buttons
for (var i:int = 0; i < 4; i++) {
for (var u:int = 0; u < 3; u++) {
var shapeButton:MovieClip = new edit_shape();
shapeButton.x = 528 + u * 62;
shapeButton.y = 15 + i * 84;
addChild(shapeButton);
shapeButton.bg.alpha = 0.3;
shapeButton.shape.gotoAndStop(3 * i + u + 1);
shapeButtons.push(shapeButton);
shapeButton.addEventListener(MouseEvent.ROLL_OVER, buttonOver);
shapeButton.addEventListener(MouseEvent.ROLL_OUT, buttonOut);
}
}

// buttons
btn_mainmenu.addEventListener(MouseEvent.CLICK, doMainmenu);
btn_reset.addEventListener(MouseEvent.CLICK, function():void{newLevel()});

// new level
newLevel();

addChild(gridShape);
addChild(canPutShape);
}

private function onMouseMove(evt:MouseEvent):void {
if(mapGrid.length>0){
var mousePos:Point = new Point(Math.floor((mouseX - gridStartX) / gridCellWidth), Math.floor((mouseY - gridStartY) / gridCellWidth));
canPutShape.x = mousePos.x * gridCellWidth + gridStartX;
canPutShape.y = mousePos.y * gridCellWidth + gridStartY;
if (mousePos.x < mapGrid[0].length && mousePos.y < mapGrid.length && mousePos.x >= 0 && mousePos.y >= 0) {
canPutShape.alpha = 1;
}else {
canPutShape.alpha = 0;
}
}
}

private function newLevel():void {
canDraw = false;

var newScreen:MovieClip = new new_edit_screen();
addChild(newScreen);
newScreen.tWidth.restrict = "0-9";
newScreen.tHeight.restrict = "0-9";
newScreen.tWidth.text = 10;
newScreen.tHeight.text = 6;
newScreen.incorrect.alpha = 0;
newScreen.btn_continue.addEventListener(MouseEvent.CLICK, editContinue);

function editContinue(evt:MouseEvent):void {
if (newScreen.tWidth.text == "" || newScreen.tHeight.text == "" || newScreen.tWidth.text == "0" || newScreen.tHeight.text == "0") {
newScreen.incorrect.alpha = 1;
return;
}
newScreen.parent.removeChild(newScreen);
mapGrid = [];
var width:int = newScreen.tWidth.text;
var height:int = newScreen.tHeight.text;
for (var i:int = 0; i < height; i++) {
mapGrid[i] = [];
for (var u:int = 0; u < width; u++) {
mapGrid[i][u] = 1;
}
}
// grid settings
calculateGrid();
gridShape.x = gridStartX;
gridShape.y = gridStartY;

// draw tiles
drawGrid();

// canPutShape settings
canPutShape.graphics.clear();
canPutShape.graphics.lineStyle(2, 0xff0000);
canPutShape.graphics.drawRect(0, 0, gridCellWidth, gridCellWidth);
canPutShape.alpha = 0;

canDraw = true;
}
}

private function calculateGrid():void {
var columns:int = mapGrid[0].length;
var rows:int = mapGrid.length;

// free size: 520x460
// fit in: 510x450

// calculate width of a cell:
gridCellWidth = Math.round(510 / columns);

var width:int = columns * gridCellWidth;
var height:int = rows * gridCellWidth;

// calculate side margin
gridStartX = (520 - width) / 2;

if (height < 450) {
gridStartY = (450 - height) / 2;
}
if (height >= 450) {
gridCellWidth = Math.round(450 / rows);
height = rows * gridCellWidth;
width = columns * gridCellWidth;
gridStartY = (460 - height) / 2;
gridStartX = (520 - width) / 2;
}
}

private function drawGrid():void {
gridShape.graphics.clear();
var width:int = mapGrid[0].length;
var height:int = mapGrid.length;

var i:int;
var u:int;

// draw background
for (i = 0; i < height; i++) {
for (u = 0; u < width; u++) {
if (mapGrid[i][u] == 1) drawCell(u, i, 0xffffff, 1, 0x999999);
}
}
}

private function drawCell(width:int, height:int, fill:uint, thick:Number, line:uint):void {
gridShape.graphics.beginFill(fill);
gridShape.graphics.lineStyle(thick, line);
gridShape.graphics.drawRect(width * gridCellWidth, height * gridCellWidth, gridCellWidth, gridCellWidth);
}

private function buttonOver(evt:MouseEvent):void {
evt.currentTarget.bg.alpha = 1;
}

private function buttonOut(evt:MouseEvent):void {
evt.currentTarget.bg.alpha = 0.3;
}

private function doMainmenu(evt:MouseEvent):void {
(root as MovieClip).gotoAndStop(1);
}

private function onMouseDown(evt:MouseEvent):void {
mouseDown = true;
}

private function onMouseUp(evt:MouseEvent):void {
mouseDown = false;
currentCell = new Point(-1, -1)
}

private function onEnterFrame(evt:Event):void {
// if drawing is allowed and mouse is down
if (canDraw && mouseDown) {
var mousePos:Point = new Point(Math.floor((mouseX - gridStartX) / gridCellWidth), Math.floor((mouseY - gridStartY) / gridCellWidth));
// if valid coordinates
if (mousePos.x < mapGrid[0].length && mousePos.y < mapGrid.length && mousePos.x >= 0 && mousePos.y >= 0) {
// if the cell is not "current cell"
if (mousePos.x != currentCell.x || mousePos.y != currentCell.y) {
currentCell.x = mousePos.x;
currentCell.y = mousePos.y;
if (mapGrid[mousePos.y][mousePos.x] == 1) {
mapGrid[mousePos.y][mousePos.x] = 0;
}else {
mapGrid[mousePos.y][mousePos.x] = 1;
}
drawGrid();
}
}
}
}

}

}

Thanks for reading!

The results:

Read more »

PhoneGap creating forms and validating forms example using jquerymobile

Hi  friends,


I am going to explain you how to create forms and validate them according to input.

Title: Creating forms using jquerymobile and validating them and sending request to server and getting some response from server.

Here is the project structure :

 colors.css

label
.missing
{
color:#FF0000;
font-weight:bold;
}
 
wait.gif
 
Add the following image
 


 
index.html
 
<!
DOCTYPE html>
<
html>
<head>
<title>New Claim</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a2/jquery.mobile-1.0a2.min.css" />
<link rel="stylesheet" href="css/colors.css">
<script src="http://code.jquery.com/jquery-1.4.4.min.js"></script>
<script src="http://code.jquery.com/mobile/1.0a2/jquery.mobile-1.0a2.min.js"></script>
<script>
// Global declarations - assignments made in $(document).ready() below
var hdrMainvar = null;
var contentMainVar = null;
var ftrMainVar = null;
var contentTransitionVar = null;
var stateLabelVar = null;
var whatLabelVar = null;
var stateVar = null;
var whatVar = null;
var form1var = null;
var confirmationVar = null;
var contentDialogVar = null;
var hdrConfirmationVar = null;
var contentConfirmationVar = null;
var ftrConfirmationVar = null;
var inputMapVar = null;
// Constants
var MISSING = "missing";
var EMPTY = "";
var NO_STATE = "ZZ";
</script>
</
head>
<
body>
<!-- Page starts here -->
<
div data-role="page" data-theme="a" id="page1">
<div data-role="header" id="hdrMain" name="hdrMain" data-nobackbtn="true">
<h1>Simple Registration</h1>
</div>
<div data-role="content" id="contentMain" name="contentMain">
<form id="form1">
<div id="shipDiv" data-role="fieldcontain">
<label for="title">Title*</label>
<input id="title" name="title_r" type="text" />
</div>
<div id="fnameDiv" data-role="fieldcontain">
<label for="fname" id="fnameLabel" name="fnameLabel">First name*</label>
<input id="fname" name="fname_r" type="text" />
</div>
<div id="lnameDiv" data-role="fieldcontain">
<label for="lname">Last name*</label>
<input id="lname" name="lname_r" type="text" />
</div>
<div id="emailDiv" data-role="fieldcontain">
<label for="email">Email*</label>
<input id="email" name="email_r" type="text" />
</div>
<div id="phoneDiv" data-role="fieldcontain">
<label for="phone">Phone</label>
<input id="phone" name="phone" type="text"/>
</div>
<div id="streetDiv" data-role="fieldcontain">
<label for="street">Street address*</label>
<input id="street" name="street_r" type="text" />
</div>
<div id="cityDiv" data-role="fieldcontain">
<label for="city">City*</label>
<input id="city" name="city_r" type="text" />
</div>
<div id="stateDiv" data-role="fieldcontain">
<label id="stateLabel" for="state">State*</label>
<select id="state" name="state_r" tabindex="2">
<option value="ZZ">Please select a state</option>
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
<option value="AR">Arkansas</option>
<option value="CA">California</option>
<option value="CO">Colorado</option>
<option value="CT">Connecticut</option>
<option value="DE">Delaware</option>
<option value="FL">Florida</option>
<option value="GA">Georgia</option>
<option value="HI">Hawaii</option>
<option value="ID">Idaho</option>
<option value="IL">Illinois</option>
<option value="IN">Indiana</option>
<option value="IA">Iowa</option>
<option value="KS">Kansas</option>
<option value="KY">Kentucky</option>
<option value="LA">Louisiana</option>
<option value="ME">Maine</option>
<option value="MD">Maryland</option>
<option value="MA">Massachusetts</option>
<option value="MI">Michigan</option>
<option value="MN">Minnesota</option>
<option value="MS">Mississippi</option>
<option value="MO">Missouri</option>
<option value="MT">Montana</option>
<option value="NE">Nebraska</option>
<option value="NV">Nevada</option>
<option value="NH">New Hampshire</option>
<option value="NJ">New Jersey</option>
<option value="NM">New Mexico</option>
<option value="NY">New York</option>
<option value="NC">North Carolina</option>
<option value="ND">North Dakota</option>
<option value="OH">Ohio</option>
<option value="OK">Oklahoma</option>
<option value="OR">Oregon</option>
<option value="PA">Pennsylvania</option>
<option value="RI">Rhode Island</option>
<option value="SC">South Carolina</option>
<option value="SD">South Dakota</option>
<option value="TN">Tennessee</option>
<option value="TX">Texas</option>
<option value="UT">Utah</option>
<option value="VT">Vermont</option>
<option value="VA">Virginia</option>
<option value="WA">Washington</option>
<option value="WV">West Virginia</option>
<option value="WI">Wisconsin</option>
<option value="WY">Wyoming</option>
</select>
</div>
<div id="zipDiv" data-role="fieldcontain">
<label for="zip">Postal code*</label>
<input id="zip" name="zip_r" type="text"/>
</div>
<div id="whatDiv" data-role="fieldcontain">
<label id="whatLabel" for="what">Please explain what happened*:</label>
<textarea cols="40" rows="8" id="what" name="what_r"></textarea>
</div>
<div id="submitDiv" data-role="fieldcontain">
<input type="submit" value="Submit Claim" data-inline="true"/>
</div>
</form>
</div><!-- contentMain -->
<div data-role="footer" id="ftrMain" name="ftrMain"></div>
<div align="CENTER" data-role="content" id="contentDialog" name="contentDialog">
<div>Please fill in all required fields before submitting the form.</div>
<a id="buttonOK" name="buttonOK" href="#page1" data-role="button" data-inline="true">OK</a>
</div> <!-- contentDialog -->
<!-- contentTransition is displayed after the form is submitted until a response is received back. -->
<div data-role="content" id="contentTransition" name="contentTransition">
<div align="CENTER"><h4>Your claim has been sent. Please wait.</h4></div>
<div align="CENTER"><img id="spin" name="spin" src="img/wait.gif"/></div>
</div> <!-- contentTransition -->
<!-- Although stored within page1 div tag, hdrConfirmation, contentConfirmation and ftrConfirmation represent a self contained confirmation page -->
<div data-role="header" id="hdrConfirmation" name="hdrConfirmation" data-nobackbtn="true">
<h1>Claim Created</h1>
</div>
<div data-role="content" id="contentConfirmation" name="contentConfirmation" align="center">
<p>A new claim has been created based on data you have submitted.</p>
<p>Your confirmation number is: <span id="confirmation" name="confirmation"></span> </p>
</div><!-- contentConfirmation -->
<div data-role="footer" id="ftrConfirmation" name="ftrConfirmation"></div>
<script>
$(document).ready(
function() {
// Assign global variables
hdrMainVar = $(
#hdrMain);
contentMainVar = $(
#contentMain);
ftrMainVar = $(
#ftrMain);
contentTransitionVar = $(
#contentTransition);
stateLabelVar = $(
#stateLabel);
whatLabelVar = $(
#whatLabel);
stateVar = $(
#state);
whatVar = $(
#what);
form1Var = $(
#form1);
confirmationVar = $(
#confirmation);
contentDialogVar = $(
#contentDialog);
hdrConfirmationVar = $(
#hdrConfirmation);
contentConfirmationVar = $(
#contentConfirmation);
ftrConfirmationVar = $(
#ftrConfirmation);
inputMapVar = $(
input[name*="_r"]);
hideContentDialog();
hideContentTransition();
hideConfirmation();
});
$(
#buttonOK).click(function() {
hideContentDialog();
showMain();
return false;
});
$(
#form1).submit(function() {
var err = false;
// Hide the Main content
hideMain();
// Reset the previously highlighted form elements
stateLabelVar.removeClass(MISSING);
whatLabelVar.removeClass(MISSING);
inputMapVar.each(
function(index){
$(
this).prev().removeClass(MISSING);
});
// Perform form validation
inputMapVar.each(
function(index){
if($(this).val()==null || $(this).val()==EMPTY){
$(
this).prev().addClass(MISSING);
err =
true;
}
});
if(stateVar.val()==NO_STATE){
stateLabelVar.addClass(MISSING);
err =
true;
}
if(whatVar.val()==null||whatVar.val()==EMPTY){
whatLabelVar.addClass(MISSING);
err =
true;
}
// If validation fails, show Dialog content
if(err == true){
showContentDialog();
return false;
}
// If validation passes, show Transition content
showContentTransition();
// Submit the form
$.post(
"requestProcessor.php", form1Var.serialize(), function(data){
confirmationVar.text(data);
hideContentTransition();
showConfirmation();
});
return false;
});
function hideMain(){
hdrMainVar.hide();
contentMainVar.hide();
ftrMainVar.hide();
}
function showMain(){
hdrMainVar.show();
contentMainVar.show();
ftrMainVar.show();
}
function hideContentTransition(){
contentTransitionVar.hide();
}
function showContentTransition(){
contentTransitionVar.show();
}
function hideContentDialog(){
contentDialogVar.hide();
}
function showContentDialog(){
contentDialogVar.show();
}
function hideConfirmation(){
hdrConfirmationVar.hide();
contentConfirmationVar.hide();
ftrConfirmationVar.hide();
}
function showConfirmation(){
hdrConfirmationVar.show();
contentConfirmationVar.show();
ftrConfirmationVar.show();
}
</script>
</
div> <!-- page1 -->
 
<!-- Page ends here -->
</
body>
</
html>
 

OutPut





Read more »