Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-18-2013, 04:25 PM   PM User | #1
RakiZtahX
New to the CF scene

 
Join Date: Feb 2013
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
RakiZtahX is an unknown quantity at this point
how to save in local storage? (html 5 new features)

i want to save an info in local storage and post it under the table.. how can i do that?

<html>
<head>
<title>Offline App(Traffic Enforcement)</title>
<link rel="stylesheet" type="text/css" title="Preferred" href="popAddVio.css" />

<script type="text.javascript">


function save() {
try {
var date = document.getElementById('textDate').value;
var plate = document.getElementById('textPlate').value;
var name = document.getElementById('textName').value;
var address = document.getElementById('textAddress').value;

localStorage.lDate = date;
localStorage.lPlate = plate;
localStorage.lName = name;
localStorage.lAddress = address;

} catch (e) {
alert("Error save");
}
}
function load() {

var storedValue = localStorage.lDate;
if (storedValue) {
document.getElementById('date').value = storedValue;
}
}
</script>
</head>

<body >

<header>
<h1>Add Violations</h1>
</header>

<div id="vioForm">
<form>
<table border="0" width="400" align="center">
<tr>
<td><label>Date:</label></td>
<td><input id="vioDate" type="date" name="textDate" value="2011-01-13"/></td>
</tr>
<tr>
<td><label>Plate #:</label></td>
<td><input id="vioPlate" type="text" name="textPlate"</td>
<tr>
<td><label>Driver's Name:</label></td>
<td><input id="vioName" type="text" name="textName" /></td>
</tr>
<tr>
<td><label>Address:</label></td>
<td><input id="vioAddress" type="text" name="textAddress"/></td>
</tr>
<tr>
<td><label>Violation:</label></td>
<td><select id="combo">
<option value="move"> Moving Violation </option>
<option value="park"> Parking Violation </option>
</select></td>
</tr>

</table>
</form>
</div>

<div>
<form id="buttons">
<input type="button" value="SAVE" onclick="save()" />
<input type="button" value="CLOSE" onclick="window.close()" />
</form>
</div>




</body>
</html>
RakiZtahX is offline   Reply With Quote
Old 02-18-2013, 05:16 PM   PM User | #2
WolfShade
Regular Coder

 
Join Date: Apr 2012
Location: St. Louis, MO, USA
Posts: 950
Thanks: 7
Thanked 98 Times in 98 Posts
WolfShade is an unknown quantity at this point
Code:
var storage, fail, uid;
try{
  uid = new Date();
  storage = window.localStorage;
  storage.setItem(uid,uid);
  fail = storage.getItem(uid) != uid;
  storage.removeItem(uid);
  fail && (storage = false);
  }catch(e){}

if(storage){ alert("Storage YES"); } else { alert("Nope.. ain't happenin'"); }
Upload to a server; this will let you know if localStorage is working.

localStorage is set: storage.setItem() (based upon the variable 'storage', set above)
localStorage is get: storage.getItem()
__________________
^_^

If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
*
The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".
WolfShade is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:25 PM.


Advertisement
Log in to turn off these ads.