 |

|
Liquor on 7:00 AM? I doubt it. It was just too early for world to make sense! People are not make to wake up on such cruel hours!
No more Mister Nice Guy... >: |
|
|
|
|

|
I had this form validating now it won't even run the first function. Any suggestions?
function formValidation()
{
var uid = document.registration.userid;
var uname = document.registration.username;
var uadd = document.registration.address;
var uzip = document.registration.zip;
var uemail = document.registration.email;
if(userid_validation(uid))
{
if(allLetter(uname))
{
if(alphanumeric(uadd))
{
if(allnumeric(uzip))
{
if(ValidateEmail(uemail))
{
}
}
}
}
return false;
}
function userid_validation(uid)
{
var letters = /^[A-Za-z]+$/;
var uid_len = uid.value.length;
if (uid.value.match(letters))
{
return true;
}
else
{
alert("The First Name can not be empty/must contain only letters");
uid.focus();
return false;
}
}
function allLetter(uname)
{
var letters = /^[A-Za-z]+$/;
if (uname.value.match(letters))
{
return true;
}
else
{
alert("The Last Name can not be empty/must contain only letters");
uname.focus();
return false;
}
}
function alphanumeric(uadd, num)
{
var uadd_len = uadd.value.length;
var numbers = /^[0-9]+$/;
if (uadd.value.match(numbers))
{
return true;
}
else
{
alert("Your phone number must have a 10 digits all numbers");
uadd.focus();
return false;
}
}
function allnumeric(uzip)
{
var numbers = /^[0-9]+$/;
if (uzip.value.match(numbers))
{
return true;
}
else
{
alert("You must fill in your ZIP code with five numeric characters");
uzip.focus();
return false;
}
}
function ValidateEmail(uemail)
{
var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
if(uemail.value.match(mailformat))
{
alert("Form Succesfully Submitted");
window.location.reload();
return true;
}
else
{
alert("You have entered an invalid email address!");
uemail.focus();
return false;
}
}
chrishoy78@gmail.com
|
|
|
|

|
Your first block of if statements does not seem correct. It can either return false or fall through to the remaining functions.
One of these days I'm going to think of a really clever signature.
|
|
|
|

|
Thanks a ton I finally put all validated that form. Good call.
|
|
|
|

|
therainking78 wrote: if(ValidateEmail(uemail))
{
I don't see a closing '}' for this '{'
Schenectady? What am I doing in Schenectady?
|
|
|
|

|
Thanks I turned on brace matching for vs2010 and picked up on it. Appreciate it.
|
|
|
|

|
Hi
i am working on traffic exchange website need little help on two points.
When user click on surf button then it will get urls from DB and start showing them in popup window now the problem i am having is that how i can get next url from DB as i cant get all as there can be more then 10K+ and also next url should open in same popup and how to add points into user account after countdown to 0seconds.
|
|
|
|

|
Look into the .ajax method from JQuery, it will let you make an asychrnous call to get the next URL from the Db.
I don't know much about what technology you're using, but you could do something like this:
$(document).ready(function() {
$(#surf).click(function() {
setInterval(GetNextUrlAndDisplayIt, 1000);
});
});
function GetNextUrlAndDisplayIt() {
$.ajax(
{
url: 'UrlForGettingNextURL.aspx',
cache: false,
success: function(data) {
window.open(data, "myWindow")
}
}
Calling window.open and using the same name will mean it will open the next URL in the same window.
I'm making a few assumptions here, like that your "surf" button has the id "surf" and that your call to get the next URL returns just the URL and there's no parsing needed.
All in all that code should get you started.
EDIT: Obviously you will need to have some kind of way to know which URL you retreived last as well.
|
|
|
|

|
i want develop a circuit diagram draw in online in my project module. like this
circuitlab[^]
Have any opensource jquery library for make this.please welcome, if have any more suggestion.
|
|
|
|

|
Open source library for this... I very much doubt it.
No more Mister Nice Guy... >: |
|
|
|
|

|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<script language="JavaScript">
function b2_clear() {
document.getElementById('second').length = 0;
}
function move_first_to_second(value) {
var len = document.getElementById('second').length;
var list=document.getElementById('second');
var i = 0, c = 0;
if (len == 0) {
list.options[list.length] = new Option(value);
len = 1;
}
else {
for (i = 0; i < list.length; i++)
if(list[i].value == value){
c++;
}
if(c>0){
c=0;
}
else{
list.options[list.length]=new Option(value);
}
}
}
</script>
<form name="form1" method="" action="">
<select name="first" id="first" size="5">
<option>Choose 1</option>
<option>Choose 2</option>
<option>Choose 3</option>
<option>Choose 4</option>
<option>Choose 5</option>
</select>
<input type="button" id="move" value=">" onclick="move_first_to_second(document.getElementById('first').value);">
<select name="second" id="second" size="3">
</select>
</form>
<input type="button" id="b2" value="clear"
önclick="b2_clear();">
</html>
|
|
|
|

|
How does Yandex do its trick? I want to programatically get the contents of a Yandex.com search result. The proglem is that a search page url does not change when you do a search on yandex.com and advance to see more pages. It must be done somehow by javascript. Any ideas?
|
|
|
|

|
Have you ever heard of AJAX[^]?
I personally like jQuery.ajax[^] since it takes away the pain of having to deal with cross browser compatibility.
W3Schools.com[^] has a plethora of AJAX examples[^].
Regards,
— Manfred
"I had the right to remain silent, but I didn't have the ability!"
Ron White, Comedian
modified 15 Nov '12 - 2:59.
|
|
|
|

|
im trying to display record from my database but based on startofTime and endofTime. any idea how in easyway to display it and im trying to use timepicker but im not really pro to use it...here my data looks like
2012-09-08 12:09:33 roadA
2012-09-08 10:49:09 roadA
2012-09-08 10:39:27 roadC
2012-09-08 09:09:33 roadA
if i select 10:39:27 to 12:09:33, then only 3 data will be display...
|
|
|
|

|
How many do you expect?
One of these days I'm going to think of a really clever signature.
|
|
|
|

|
Hi,
I have a scenario where I have to enter a date in a text box in MM/DD/YYYY format and there is another text box where the value should be filled by itself and the value must be exactly one month from the entered date i.e, if my value in the first text box is 05/07/2012 second text box should automatically possess 05/08/2012 and this should be done by javascript, below is the code I tried but the second text box is taking the same value as the first text box, can someone please help me out with this issue and tell me what's wrong with the code
function populateArchiveDate() {
var frm=document.form1
if (validateDateFormat(frm.story_intro_date) && frm.story_exp_date.disabled == false) {
var post_date = new Date(frm.story_intro_date.value);
alert(post_date.getMonth());
var expiration_date = new Date(post_date.setMonth(post_date.getMonth() + 1));
alert(expiration_date.getMonth());
if (expiration_date.getMonth() == 0)
expiration_date = expiration_date.getMonth() + 1 + "/" + expiration_date.getDate() + "/" + expiration_date.getFullYear();
else
expiration_date = expiration_date.getMonth() + "/" + expiration_date.getDate() + "/" + expiration_date.getFullYear();
frm.story_exp_date.value = expiration_date;
frm.hdn_story_exp_date.value = expiration_date;
Thanks in advance
|
|
|
|

|
SadiqMohammed wrote: if (expiration_date.getMonth() == 0)
expiration_date = expiration_date.getMonth() + 1 + "/" + expiration_date.getDate() + "/" + expiration_date.getFullYear();
else
expiration_date = expiration_date.getMonth() + "/" + expiration_date.getDate() + "/" + expiration_date.getFullYear();
There's your problem - in Javascript, months run from 0 to 11, not 1 to 12. If the new date is in January, you're setting the result correctly; otherwise, you're setting it to the previous month.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|

|
@Richard : I changed it and considering that Javascript takes month index as 0 to 11 but now when I enter the date as 01/31/2012 the value in the next text box is 04/01/2012 but for rest of the months I'm getting the desired solution
All Izzz Wellll
|
|
|
|

|
I don't know how you've managed to get 1st April; with the code below, I get 2nd March:
var post_date = new Date(2012, 0, 31);
var expiration_date = new Date(post_date.setMonth(post_date.getMonth() + 1));
expiration_date = expiration_date.getMonth() + 1 + "/" + expiration_date.getDate() + "/" + expiration_date.getFullYear();
alert(expiration_date);
The reason it's 2nd March is that there is no 31st February. If you want the expiration_date to always be a date within the following month, you'll need to check that manually:
var post_date = new Date(2012, 0, 31);
var firstOfMonth = new Date(post_date);
firstOfMonth.setDate(1);
firstOfMonth.setMonth(post_date.getMonth() + 1);
var expiration_date = new Date(firstOfMonth);
expiration_date.setDate(post_date.getDate());
while (expiration_date.getMonth() != firstOfMonth.getMonth())
{
expiration_date.setDate(expiration_date.getDate() - 1);
}
expiration_date = expiration_date.getMonth() + 1 + "/" + expiration_date.getDate() + "/" + expiration_date.getFullYear();
alert(expiration_date);
Alternatively, you could look at the Datejs library[^].
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|

|
Hi Richard,
Thanks for the suggestion I solved the problem and I'm getting the desired result, I faced a problem only for the month of November i.e, 11th month but I resolved it using the following code with the help of a if block
function populateArchive() {
var frm=document.form1;
var input;
var monthVal;
var monthMax = new Array(31,31,29,31,30,31,30,31,31,30,31,30,31);
var top ;
if (validateDateFormat(frm.story_intro_date) && frm.story_exp_date.disabled == false) {
var post_date = new Date(frm.story_intro_date.value);
var expiration_date = new Date(post_date.setMonth(post_date.getMonth() ));
var new_date = expiration_date.getDate();
var new_month = expiration_date.getMonth()+ 2;
var new_year = expiration_date.getFullYear();
if (new_month == 13) {
new_month = new_month - 12;
new_year = new_year + 1;
}
input = parseInt(new_date, 10);
monthVal = new_month;
top = monthMax[monthVal];
if (!inRange(input, 1, top)) {
expiration_date_new = new_month + "/" + top + "/" + new_year;
}
else
expiration_date_new = new_month + "/" + new_date + "/" + new_year;
frm.story_exp_date.value = expiration_date_new;
frm.hdn_story_exp_date.value = expiration_date_new;
}
}
thanks for ur suggestions once again
|
|
|
|

|
try this code its working well.
$(function () {
$('#date2').focus(function () {
var istDateVal = $("#date1").val().split("/");
var istDate = new Date();
istDate.setFullYear(istDateVal[2], istDateVal[1] - 1, istDateVal[0]);
istDate.setMonth(istDate.getMonth() - 1);
$('#date2').val(istDate.getDate() + "/" + (istDate.getMonth() + 1) + "/" + istDate.getFullYear())
});
});
|
|
|
|

|
... and in December, what happens?
Peter
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|

|
I didnt get you bro. what is your concern. Will you elaborate it.
deepak.m.shrma
|
|
|
|

|
I have a problem to pass a javascript object variable value to mysql database.
I dont really code in javascript and i dont know what is wrong.
I make an object variable. With this object i make 4 properties and then make some calculations that show some values. I need to take the results values to mysql database.
I searched in google and i found that i need ajax to do that.
But it doesnt work. I dont have experience in ajax either.
I will show you the code and hope anyone can help me
This is the Javascript code:
<script language="javascript" type="text/javascript">
function ajaxFunction(){
var ajaxRequest;
try{
ajaxRequest = new XMLHttpRequest();
} catch (e){
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
alert("Your browser broke!");
return false;
}
}
}
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
document.myForm.time.value = ajaxRequest.responseText;
}
}
<!-- Getting the end time
ds = new Date();
e_time = ds.getTime();
var res = new Object();
res.bytes_transfered =document.getElementById('age').value <? echo strlen($random_string); ?>;
res.total_time_seconds = (e_time-s_time)/1000;
res.generatied_in = <? echo round($stop_time - $start_time, 5); ?>;
res.ip = "<? echo $_SERVER['REMOTE_ADDR'].' ['.gethostbyaddr($_SERVER['REMOTE_ADDR']).']'; ?>";
-->
var queryString = "?res.bytes_transfered=" + res.bytes_transfered + "&res.total_time_seconds=" + res.total_time_seconds + "&res.generatied_in =" + res.generatied_in + "&res.ip =" + res.ip;
ajaxRequest.open("GET", "insert.php" + queryString, true);
ajaxRequest.send(null);
new Ajax.Request('insert.php', {
onSuccess : function(xmlHTTP) {
eval(mlHTTP.responseText);
}
});
</script>
This is the insert.php file
<?php
$fecha= date("Y-m-d H:i:s");
$connnect= mysql_connect("localhost", "root", "123456");
mysql_select_db("dbname");
$res.bytes_transfered= mysql_real_escape_string($_GET['res.bytes_transfered']);
$res.total_time_seconds= mysql_real_escape_string($_GET['res.total_time_seconds']);
$res.generatied_in= mysql_real_escape_string($_GET['res.generatied_in']);
$res.ip= mysql_real_escape_string($_GET['res.ip']);
$queryreg=mysql_query("INSERT INTO grafico(Cantidad, Tiempo, IP, Bajada, Subida) VALUES ('$res.bytes_transfered','$res.total_time_seconds','$res.generatied_in','$res.ip=','0',$fecha) ");
if (!$queryreg) {
die('No se ha podido ingresar su registro.');
}
else{
die("Usted se ha registrado exitosamente!");
}
?>
I hope that someone can help me!
|
|
|
|

|
Don't reinvate a wheel. Use jQuery ajax function or something similar.
No more Mister Nice Guy... >: |
|
|
|
|

|
Thank you for your response!
But my problem is how can i do that? Can you show me how? Because i´m a newbie in javascript/ajax and i dont understand what is wrong with the code.
|
|
|
|

|
You didn't include any errors. It's been a while since I wrote any php (and I am glad... ) so it may be rusty but I don't see any obvious deficiencies.
Read this: []
It will decrease length of your code and with it maybe some bugs will disappear.
Another thing is that I don't see any reason to send client IP address back and forth (REMOTE_ADDRESS that it is for right?).
I will never change between postbacks so why are you inserting it in JS just to send it back to server?
No more Mister Nice Guy... >: |
|
|
|
|
|

|
Why you just do a service in php? And in the js make a post something like that maybe:
var DataToSend = new object();
DataToSend.name = $('#textName').val();
$.post('myservice.php',DataToSend,function(response) {
alert(response);
});
|
|
|
|

|
Hello,
I try to find a solution how to inform a user (in front of a display) that content of a web application has changed when a user has minimized a browser window (on a task bar).
My web application periodically refresh its content and I would like to inform a user if the content is changed.
Does anybody know the solution.
Thank you.
|
|
|
|

|
I would imagine a simple alert() would at least make the title bar blink in the task bar.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|

|
Hello All,
I'm beginner for JavaScript, I need a script for unzip the .gzip files and gzip the any files.I created one application in HTML5 and want to merge above functionality.
Can anyone help me out!
Thanks
modified 1 Nov '12 - 8:32.
|
|
|
|
|

|
for the footer i have used the concept of sticky footer.
When i increased the height of textarea instead of creating a vertical scroll bar.. it increased and hid behind the footer and when i increased further the vertical scroll bar came when it met the end of the page.
Even when i used developer tools then then footer is shifted upwards
Can someone please help me out. The demo page is up and running.
the link is http://widgetdemo.webatu.com/
-Abhishek
|
|
|
|

|
Use
{
height:auto;
}
on all parents of textarea.
And set
{
position:relative;
}
on footer.
This will cause content to stretch to textarea height.
No more Mister Nice Guy... >: |
modified 31 Oct '12 - 4:00.
|
|
|
|
|

|
if i ll give
{ position: relative;}
for footer then it wont stick to the bottom of the page.
Its working fine with position as absolute only and {height: auto;} on all the parents of text area.
|
|
|
|

|
Hm... Can you update your demo? Then I'll into that.
No more Mister Nice Guy... >: |
|
|
|
|

|
i think i have already updated the demo.. I checked in the developer tool there is an extra div getting added to the DOM.
This i guess is because of the hosting problem.
I tried to delete the the node from the developer tool. And then the problem went off.
Thanks
sent from mobile
|
|
|
|

|
If everything went well, then I am happy, that this help. No problem
No more Mister Nice Guy... >: |
|
|
|
|

|
Hi.. Can anyone provide some working example of calling a java webservice method(simple helloworld method) from javascript.
|
|
|
|
|

|
There are a ton of examples but I would certainly recommend using jquery[^]
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|

|
By using Json() method we can send data to webmethod from the javascript.
|
|
|
|

|
org.mozilla.javascript.EcmaError: ReferenceError: "ActiveXObject" is not defined
Friends have encountered this kind of problem, I use ie8, Internet options security Settings for this part set I set, no, can you tell me how to solve? Please specify, thank you!
|
|
|
|

|
Say what?
Simple. You have a website that uses an ActiveX object. When you view this on your computer it is okay, you use IE8.
When your friends try to view it using FF, they get a message that says ActiveXObject isn't defined.
You wanna know why?
Easy, only (that's only, only, only or ONLY) Mirosoft Internet Explorer supports them.
There are precisely 2 options in this case:
1) Avoid using an ActiveXObject.
2) Force your friends to use IE.
I'll leave it to you to decide which is the least unpalatable..
(99%+ of the rest of the world went with option 1 btw)
Make it work. Then do it better - Andrei Straut
|
|
|
|

|
I got a problem with arrays in js and I'm starting to lose it.
Every iteration generates a different value.
However, it appears that it pushes the same value in the entire row; so the entire row has the same "random" value every time.
I want to have every 'x' to have a "random" value.
for (var x = 0; x <= 90; x++) {
var col = CustomRandom();
memBlock[x, 68] = Math.floor(col.next() * 255);
}
The "2D" Array is created with a recursive function I found on the web:
function createMemblock(length) {
var a = new Array(length || 0);
if (arguments.length > 1) {
var args = Array.prototype.slice(arguments, 1);
for (var i = 0; i < length; i++) {
a[i] = createMemblock.apply(this, args);
}
}
return a;
}
And here is the entire script, just in case:
window.requestAnimFrame = (function (callback) {
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function (callback) {
window.setTimeout(callback, 1000 / 60);
};
})();
function createMemblock(length) {
var a = new Array(length || 0);
if (arguments.length > 1) {
var args = Array.prototype.slice(arguments, 1);
for (var i = 0; i < length; i++) {
a[i] = createMemblock.apply(this, args);
}
}
return a;
}
var CustomRandom = function (nseed) {
var seed, constant = Math.pow(2, 13) + 1, prime = 1987,
maximum = 1000;
if (nseed) {
seed = nseed;
}
if (seed == null) {
seed = (new Date()).getTime();
}
return {
next: function (min, max) {
seed *= constant;
seed += prime;
return min && max ? min + seed % maximum / maximum * (max - min) : seed % maximum / maximum;
}
}
}
function getColor(R, G, B) {
var s = "#";
if (R <= 15) {
s += "0";
}
s += R.toString(16);
if (G <= 15) {
s += "0";
}
s += G.toString(15);
if (B <= 15) {
s += "0";
}
s += B.toString(15);
return s;
}
function animate() {
var canvas = document.getElementById("canvas");
var context = canvas.getContext("2d");
for (var y = 0; y <= 67; y++) {
for (var x = 1; x <= 89; x++) {
memBlock[x, y] = (memBlock[x - 1, y + 1] + memBlock[x + 1, y + 1]) / 2;
}
}
for (var x = 0; x <= 90; x++) {
var col = CustomRandom();
memBlock[x, 68] = Math.floor(col.next() * 255);
}
for (var y = 0; y <= 68; y++) {
for (var x = 0; x <= 90; x++) {
context.fillStyle = getColor(memBlock[x, y], 0, 0);
context.fillRect(x * 10, y * 10-10, 10, 10);
}
}
requestAnimFrame(function () {
animate();
});
}
function InitMemblock() {
for (var x = 0; x <= 90; x++) {
for (var y = 0; y <= 68; y++) {
memBlock[x, y] = 0;
}
}
}
window.onload = function () {
InitMemblock();
animate();
};
var memBlock = createMemblock(90, 68);
It's just an experiment with the canvas API; but If I can't control a 2D-block of memory I pretty much can't do anything.
If I can't get it to work I suppose I could use a single Array; but that would really suck.
Giraffes are not real.
|
|
|
|

|
It's not so tricky to create a 2d array, you just need to go about it a little differently to some other langs. First, you want to create the first dimension. Next, you need to fill each element in this dimension with a second array.
In my case, I've abstracted a screen. The first dimension is the rows, or y-coord. Each of these rows contains an array that holds all of the pixels in that line - the columns.
This code simply creates a 320x200 array and fills it with a simple xor pattern.
Of course, the other way to do it is to do what the compiler does - simply allocate a block of memory and then index into it yourself. The imageData object of the canvas does this - it has a 1d array that represents the pixels. So (y*width*4)+(x*4) will give you the index of the pixel you want. Since it's a 32bit pixel, there's 4 bytes for each one. It saves indexing and is much quicker and easy enough enough.
That said, here's the code I promised earlier.
var screenArray;
function mInit()
{
var x, y, width=320, height=200;
var result = new Array;
for (y=0; y<height; y++)
{
result[y] = new Array;
for (x=0; x<width; x++)
{
result[y][x] = x^y;
}
}
screenArray = result;
console.log(screenArray);
}
Make it work. Then do it better - Andrei Straut
|
|
|
|

|
Dear all,
Now, I'm implementing flexigrid table using jquery, for server side script I use PHP. I've made it and run properly, but there is no clear button to reset grid table after do searching. What should I do ? So I can reset grid table after searching ? I use library flexigrid.pack.js from http://www.flexigrid.info
Thank you,
|
|
|
|

|
hello
i would appreciate a little help here
is it possible to make default pagination of my dynamic html table created from saving form elements
i need to make 15 records per page and i tried lots of plugins but i couldn't get it done
thanks
Mille
my code is:
var Animals ={
index: window.localStorage.getItem("Animals:index"),
$table: document.getElementById("animals-table"),
$form: document.getElementById("animals-form"),
$button_save: document.getElementById("animals-save"),
$button_discard: document.getElementById("animals-discard"),
init: function() {
if (!Animals.index) {
window.localStorage.setItem("Animals:index", Animals.index = 1);
}
Animals.$form.reset();
Animals.$button_discard.addEventListener("click", function(event) {
Animals.$form.reset();
Animals.$form.id_entry.value = 0;
}, true);
Animals.$form.addEventListener("submit", function(event) {
var entry = {
id: parseInt(this.id_entry.value,radix),
animal_id:this.animal_id.value,
animal_name: this.animal_name.value,
animal_type: this.animal_type.value,
bday: this.bday.value,
animal_sex: this.animal_sex.value,
mother_name: this.mother_name.value,
farm_name: this.farm_name.value,
money: this.money.value,
weight: this.weight.value,
purchase_partner: this.purchase_partner.value
};
if (entry.id === 0) {
Animals.storeAdd(entry);
Animals.tableAdd(entry);
}
else { // edit
Animals.storeEdit(entry);
Animals.tableEdit(entry);
}
this.reset();
this.id_entry.value = 0;
event.preventDefault();
}, true);
if (window.localStorage.length - 1) {
var animals_list = [], i, key;
for (i = 0; i < window.localStorage.length; i++) {
key = window.localStorage.key(i);
if (/Animals:\d+/.test(key)) {
animals_list.push(JSON.parse(window.localStorage.getItem(key)));
}
}
if (animals_list.length) {
animals_list.sort(function(a, b)
{return a.id < b.id ? -1 : (a.id > b.id ? 1 : 0);})
.forEach(Animals.tableAdd);}
}
Animals.$table.addEventListener("click", function(event) {
var op = event.target.getAttribute("data-op");
if (/edit|remove/.test(op)) {
var entry = JSON.parse(window.localStorage.getItem("Animals:"+ event.target.getAttribute("data-id")));
if (op == "edit") {
Animals.$form.id_entry.value = entry.id;
Animals.$form.animal_id.value = entry.animal_id;
Animals.$form.animal_name.value = entry.animal_name;
Animals.$form.animal_type.value = entry.animal_type;
Animals.$form.bday.value = entry.bday;
Animals.$form.animal_sex.value = entry.animal_sex;
Animals.$form.mother_name.value = entry.mother_name;
Animals.$form.farm_name.value = entry.farm_name;
Animals.$form.money.value = entry.money;
Animals.$form.weight.value = entry.weight;
Animals.$form.purchase_partner.value = entry.purchase_partner;
}
else if (op == "remove") {
if (confirm('Are you sure you want to remove this animal from your list?' )) {
Animals.storeRemove(entry);
Animals.tableRemove(entry);
}
}
event.preventDefault();
}
}, true);
},
storeAdd: function(entry) {
entry.id = Animals.index;
window.localStorage.setItem("Animals:index", ++Animals.index);
window.localStorage.setItem("Animals:"+ entry.id, JSON.stringify(entry));
},
storeEdit: function(entry) {
window.localStorage.setItem("Animals:"+ entry.id, JSON.stringify(entry));
},
storeRemove: function(entry) {
window.localStorage.removeItem("Animals:"+ entry.id);
},
tableAdd: function(entry) {
var $tr = document.createElement("tr"), $td, key;
for (key in entry) {
if (entry.hasOwnProperty(key)) {
$td = document.createElement("td");
$td.appendChild(document.createTextNode(entry[key]));
$tr.appendChild($td);
}
}
$td = document.createElement("td");
$td.innerHTML = 'Edit | Remove';
$tr.appendChild($td);
$tr.setAttribute("id", "entry-"+ entry.id);
Animals.$table.appendChild($tr);
},
tableEdit: function(entry) {
var $tr = document.getElementById("entry-"+ entry.id), $td, key;
$tr.innerHTML = "";
for (key in entry) {
if (entry.hasOwnProperty(key)) {
$td = document.createElement("td");
$td.appendChild(document.createTextNode(entry[key]));
$tr.appendChild($td);
}
}
$td = document.createElement("td");
$td.innerHTML = 'Edit | Remove';
$tr.appendChild($td);
},
tableRemove: function(entry) {
Animals.$table.removeChild(document.getElementById("entry-"+ entry.id));
}
};
Animals.init();
</script>
|
|
|
|
 |