hi, i need a javascript that determines if a year is a leap year or not, by putting the year in a text field and hitting a submit button.
i'm fairly new to all this, so would appriciate the help, ta.
12 2199
hi ...
have a look at the following thread: http://www.thescripts.com/forum/thread663618.html
kind regards
thanks gits, i'm using your code in that example, which works grand.
can you tell me what the % sign does? year % 100
also, what does flag mean?
also, in the form submit button, can you explain this code, onclick="leapYear(document.getElementById('year'). value);" gits 5,390
Expert Mod 4TB
hi ...
it's not my code ;) ... only helped to get it to work ... 3 things to mention:
1. % is the modulus-operator - have a look here
2. flag is a simple variable in that script ;) doesn't mean anything ... the poster there called it that way ...
3. consider to use the solution that jsakalos provided there ... it's shorter probably better then the other solution
kind regards
hi ...
it's not my code ;) ... only helped to get it to work ... 3 things to mention:
1. % is the modulus-operator - have a look here
2. flag is a simple variable in that script ;) doesn't mean anything ... the poster there called it that way ...
3. consider to use the solution that jsakalos provided there ... it's shorter probably better then the other solution
kind regards
i think i'd better get my head around a basic way, before i use jsakalos's version.
i have to do this in php.
here's what i understand, the user has to enter a year, this number has to be disivable by 4 with no remainders, if the year ends in a 00 it's not a leap year, unless it's every 400 years, then it is.
here's my own code so far,
i'm parsing this through a form..... - <?php
-
-
-
$leap = x % 100;
-
-
-
-
$x = $_POST["txtRequest"];
-
-
if ($leap == 0)
-
-
{
-
echo("this is a leap year");
-
}
-
-
-
else
-
{
-
-
echo("this is not a leap year");
-
}
-
-
?>
-
-
at the moment, i'm only dividing the number by 4, and seeing if the remainder is 0, this should work right? but it doesn't.
i need to get that working, and then add 2 other variables?
also, why doesn't flay have a var before it, if it is a variable?
ok, i was sure this would work........ but i'm just getting an error, am i close with this one, or am i way off? - <?php
-
-
-
$leap = $x;
-
-
-
-
$x = $_POST["year"];
-
-
if ($leap == (($x%100) == 0 || ($x%400) == 0 || ($x%4) == 0)
-
-
{
-
echo("this is a leap year");
-
}
-
-
-
else
-
{
-
-
echo("this is not a leap year");
-
}
-
-
?>
ok, i was sure this would work........ but i'm just getting an error, am i close with this one, or am i way off? - <?php
-
-
-
$leap = $x;
-
-
-
-
$x = $_POST["year"];
-
-
if ($leap == (($x%100) == 0 || ($x%400) == 0 || ($x%4) == 0)
-
-
{
-
echo("this is a leap year");
-
}
-
-
-
else
-
{
-
-
echo("this is not a leap year");
-
}
-
-
?>
what does the error say?
and i thought u wanted to do this with javascript...thats php?
what does the error say?
and i thought u wanted to do this with javascript...thats php?
i have to do it in javascript and php.......... ok here's my latest attempt, in php........ - <?php
-
-
-
$leap = $x;
-
-
-
-
$x = $_POST["year"];
-
-
if ($leap == (($x%100) == 0 || ($x%400) == 0 || ($x%4) == 0)
-
-
{
-
echo("this is a leap year");
-
}
-
-
-
else
-
{
-
-
echo("this is not a leap year");
-
}
-
-
?>
i'm not getting any errors, but basicly every year is a leap year :/
can you comment on this code, tell me if i'm anywhere close, if i'm on the right track....... i know there's probably a cleaner faster way to do this, but i'm just trying to understand conditionals.
basicly, i'm trying to say in the code, if x is divided by 4, 100 or 400, and you get a module with nothing left over, it's a leap year.
am i making any sence?
i have to do it in javascript and php.......... ok here's my latest attempt, in php........ - <?php
-
-
-
$leap = $x;
-
-
-
-
$x = $_POST["year"];
-
-
if ($leap == (($x%100) == 0 || ($x%400) == 0 || ($x%4) == 0)
-
-
{
-
echo("this is a leap year");
-
}
-
-
-
else
-
{
-
-
echo("this is not a leap year");
-
}
-
-
?>
i'm not getting any errors, but basicly every year is a leap year :/
can you comment on this code, tell me if i'm anywhere close, if i'm on the right track....... i know there's probably a cleaner faster way to do this, but i'm just trying to understand conditionals.
basicly, i'm trying to say in the code, if x is divided by 4, 100 or 400, and you get a module with nothing left over, it's a leap year.
am i making any sence?
this is it:
[php]
$x = $_POST["year"];
if (($x%4) == 0)
{
echo("this is a leap year");
}
else
{
echo("this is not a leap year");
}
[/php]
there is nothing other that that.
this is it:
[php]
$x = $_POST["year"];
if (($x%4) == 0)
{
echo("this is a leap year");
}
else
{
echo("this is not a leap year");
}
[/php]
there is nothing other that that.
ok, a little help from a guy in work, and here it is! -
-
<?php
-
-
$x = $_POST["year"];
-
-
-
$leap = $x;
-
-
-
if ( ( ($x % 4 == 0) && ($x % 100 !=0) ) || ($x % 400 == 0) )
-
-
{
-
echo("this is a leap year");
-
}
-
-
-
else
-
{
-
-
echo("this is not a leap year");
-
}
-
-
?>
my brain's still a bit fuzzy over the whole leap year thing, but i'm starting to get the whole conditional thing, oh, and i know how modules work!
inside your if, y don't u just use '%4'? y do u need '%100' or '%400'?
if it returns 0 its a leap year, if it returns anything else its not a leap year.
inside your if, y don't u just use '%4'? y do u need '%100' or '%400'?
if it returns 0 its a leap year, if it returns anything else its not a leap year.
ye, you need the other 2, as years ending in 00 is not a leap year, except for every 400 years.
If a year is evenly divisibly by 100 it is not a leap year, unless it is also evenly divisibly by 400. 1900 was not a leap year, 2000 was.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Dr John Stockton |
last post by:
I'm starting a new thread, for clarity.
I'm assuming that it's ECMA-262 3rd Edn (1999) that we should be using
for Web pages; that 4th Edn (what's its present status? is it
available?) is too...
|
by: deepak.rathore |
last post by:
can someone give the regular expr. to validate leap yr like
02/29/2000,02/29/00
Thanks
|
by: jamesyreid |
last post by:
Hi,
I'm really sorry to post this as I know it must have been asked
countless times before, but I can't find an answer anywhere.
Does anyone have a snippet of JavaScript code I could borrow...
|
by: owz |
last post by:
Ok, I am making a program (java class file) 2 work out if a date entered is valid or invalid for the day, month year, and for leap years.. dd/mm/yyyy .
I seem 2 have gotten it 2 validate the year...
|
by: rn216_ccc |
last post by:
Hi there all,
I found a web site,. http://www.onlineconversion.com/leapyear.htm,
where it can give a list of leap years by within the given range by
the user, or the user may enter a year and the...
|
by: xGx |
last post by:
Hi please could someone help. i have created this programming so you can work out if there is a LEAP YEAR. But i need it to handle centuries. heres the code
def isLeapYear (year):
result =...
|
by: cybermom |
last post by:
Hi another newbie here
I am trying to get the message: The you entered is a leap year, but it does not happen, what did I do wrong with this script?
<html>
<HEAD>
<SCRIPT...
|
by: mazwolfe |
last post by:
I'm new here, so excuse me if my style is incorrect. Can anyone come
up with a better method for this calculation?
Code:
int is_leap(int year)
{
switch (year % 19) {
case 0: case 3: case 6:...
|
by: jrw133 |
last post by:
Hello. So im a little bit stuck on one of my homework questions.
heres the question:
Write a C Shell Script that performs the following functions. Asks the user to input a year. The script...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| | |