PDA

View Full Version : JavaScript Validation?



techno_race
02-28-2007, 01:09 AM
Does anyone know of a free online place to validate your JavaScripts? I am just starting to write long JavaScripts, and most of them don't work :eek: I test mine in FX 2, IE 7 and NS 8. I write my scripts in Notepad++. The least basic script I got to work was:


var date = new Date();
var month = date.getMonth();
var showmonth;
var day = date.getDate();

switch (month) {
case 0:
showmonth = "January";
break;
...
default: showmonth = "INVALID";
}

document.write(showmonth + " " + date);

or something like that.
Basically, I'm looking for a place where you send in your JavaScript and an actual person looks at the code and fixes it so that it works.

Any help would be greatly appreciated!

boxxertrumps
02-28-2007, 01:23 AM
get firebug addon for FF.

It has a js error console.

techno_race
02-28-2007, 02:06 AM
I seriously need an actual person to do it because the person would know what I meant by something!

php-5
02-28-2007, 02:30 AM
Why not just ask someone in the forum, I sure maybe someone wouldn't mind helping....if it isn't to long:)

techno_race
03-01-2007, 12:28 AM
In that case, does anybody know why this doesn't work?

//Fruit and vegetable of the month

var computer = new Date();
var month = computer.getMonth;
var fruit;
var fv;

switch (month) {
case 0:
fruit = 'oranges';
fv = 'Fruit';
break;
case 1:
fruit = 'oranges';
fv = 'Fruit';
break;
case 2:
fruit = 'lettuce';
fv = 'Vegetable';
break;
case 3:
fruit = 'lettuce';
fv = 'Vegetable';
break;
case 4:
fruit = 'lettuce';
fv = 'Vegetable';
break;
case 5:
fruit = 'lettuce';
fv = 'Vegetable';
break;
case 6:
fruit = 'tomatoes';
fv = 'Fruit';
break;
case 7:
fruit = 'tomatoes';
fv = 'Fruit';
break;
case 8:
fruit = 'tomatoes';
fv = 'Fruit';
break;
case 9:
fruit = 'tomatoes';
fv = 'Fruit';
break;
case 10:
fruit = 'oranges';
fv = 'Fruit';
break;
case 11:
fruit = 'oranges';
fv = 'Fruit';
break;
}

document.write('The ' + fv + ' of the Month is ' + fruit + '.');

It shows up in all the browsers as nothing.
Any modifications are greatly appreciated!

Twey
03-01-2007, 12:45 AM
If you find yourself doing a numerical switch like that, you may as well use an array. The error, though, is caused by this:
var month = computer.getMonth;You don't want the function getMonth, you want its return value, so you should say getMonth().
//Fruit and vegetable of the month
var product = [
["oranges", "Fruit"],
["oranges", "Fruit"],
["lettuce", "Vegetable"],
["lettuce", "Vegetable"],
["lettuce", "Vegetable"],
["lettuce", "Vegetable"],
["tomatoes", "Fruit"],
["tomatoes", "Fruit"],
["tomatoes", "Fruit"],
["tomatoes", "Fruit"],
["oranges", "Fruit"],
["oranges", "Fruit"]
][(new Date()).getMonth()];

document.write('The ' + product[1] + ' of the Month is ' + product[0] + '.');There are various other ways this could be improved too, but not without taking it beyond beginner level.

techno_race
03-01-2007, 02:31 AM
I SERIOUSLY need help with this one. All I can get out of my computer is 'JANUARY1 is not defined.' Meaning:confused:?


var finddate = new Date();
var findmonth = finddate.getMonth();
var findday = finddate.getDate();
var holiday;
var exclaim;
var displayMonth;
var findyear = finddate.getYear();

switch (findmonth) {
case 0 :
displayMonth = "JANUARY"
break
case 1 :
displayMonth = "FEBRUARY"
break
case 2 :
displayMonth = "MARCH"
break
case 3 :
displayMonth = "APRIL"
break
case 4 :
displayMonth = "MAY"
break
case 5 :
displayMonth = "JUNE"
break
case 6 :
displayMonth = "JULY"
break
case 7 :
displayMonth = "AUGUST"
break
case 8 :
displayMonth = "SEPTEMBER"
break
case 9 :
displayMonth = "OCTOBER"
break
case 10 :
displayMonth = "NOVEMBER"
break
case 11 :
displayMonth = "DECEMBER"
break

default: displayMonth = "INVALID"
}

var findholiday = displayMonth + findday

switch (findholiday) {
case JANUARY1 :
holiday = "New Year's Day"
exclaim = "Happy " + findyear
break
case JANUARY15 :
holiday = "Martin Luther King, Jr.'s Birthday"
exclaim = "Feel the freedom"
break
case JANUARY27 :
holiday = "the Penguin Popcorn Parade"
exclaim = "Munch, munch, munch"
break
case FEBRUARY2 :
holiday = "Groundhog's Day"
exclaim = "Let's hope he'll wake up"
break
case FEBRUARY12 :
holiday = "Abraham Lincoln's Birthday"
exclaim = "Goodbye, slavery"
break
case FEBRUARY14 :
holiday = "Valentine's Day"
exclaim = "Feel the love"
break
case FEBRUARY15 :
holiday = "Petentine's Day"
exclaim = "Slurp, slurp, slurp"
break
case FEBRUARY22 :
holiday = "George Washington's Birthday"
exclaim = "Fly the flag"
break
case MARCH17 :
holiday = "St. Patrick's Day"
exclaim = "It's hard to find <i>any</i> clovers"
break
case APRIL1 :
holiday = "April Fool's Day"
exclaim = "My computer is laughing"
break
case APRIL10 :
holiday = "ASPCA's Birthday"
exclaim = "Woof, woof, woof"
break
case APRIL22 :
holiday = "Earth Day"
exclaim = "I think I use too many watts"
break
case JUNE14 :
holiday = "Flag Day"
exclaim = "Someone design an Antarctica flag"
break
case JULY4 :
holiday = "Independence Day"
exclaim = "Fireworks scare me"
break
case AUGUST29 :
holiday = "Henry Bergh's Birthday"
exclaim = "1813? Yikes"
break
case OCTOBER31 :
holiday = "Halloween"
exclaim = "Whooooooo"
break
case DECEMBER25 :
holiday = "Christmas"
exclaim = "Smell the gingerbread"
break
case DECEMBER31 :
holiday = "New Year's Eve"
exclaim = "Goodbye, " + findyear
break

default: holiday = displayMonth + " " + findday; exclaim = ""
}

document.write("It's " + holiday + "!<br><center><font class=exclamation>" + exclaim + "!</font></center></br>");
Nobody bother with <script language="JavaScript" type="text/javascript">. I did that already. I am positive that the book that taught me JavaScript said everything I did here was valid. YEAAAH, RIIIGHT!

php-5
03-01-2007, 04:26 AM
See, this forum is packed with helpful people!

Twey
03-01-2007, 04:29 PM
This time you're missing quotes :) But again, it's a lot easier to use arrays.
Nobody bother with <script language="JavaScript" type="text/javascript">. I did that already.Don't bother with language, it's deprecated :) Just type is fine.
var d = new Date(),
month = d.getMonth(),
day = d.getDate(),
year = d.getFullYear(),
humanMonth = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
][month];

var holidays = {
'1/1' : ["New Year's Day", "Happy " + year],
'1/15' : ["Martin Luther King's Birthday", "Feel the freedom"],
'1/27' : ["The Penguin Popcorn Parade", "Munch, munch, munch"], // What the heck? Haha.
'2/2' : ["Groundhog Day", "Let's hope he'll wake up"],
'2/12' : ["Abraham Lincoln's Birthday", "Goodbye, slavery"],
'2/14' : ["Valentine's Day", "Feel the love"],
'2/15' : ["Petentine's Day", "Slurp, slurp, slurp"], // Never heard of this one either...
'2/22' : ["George Washington's Birthday", "Fly the flag"],
'3/17' : ["Saint Patrick's Day", "It's hard to find <i>any</i> clovers"], // Not here :-)
'4/1' : ["April Fool's Day", "My computer is laughing"],
'4/10' : ["ASPCA's Birthday", "Woof, woof, woof"], // I'm guessing this is the equivalent of RSPCA?
'4/22' : ["Earth Day", "I think I use too many watts"],
'6/14' : ["Flag Day", "Someone design an Antarctica flag"],
'7/4' : ["Independence Day", "Fireworks scare me"],
'8/29' : ["Henry Bergh's Birthday", "1813? Yikes"],
'10/31' : ["Hallowe'en", "Whooooooo"],
'12/25' : ["Christmas", "Smell the gingerbread"],
'12/31' : ["New Year's Eve", "Goodbye, " + year]
};

var holiday = holidays[(month + 1) + "/" + day] || [humanMonth + " " + day, ""];

document.write("It's " + holiday[0] + "!<br><center><font class=exclamation>" + holiday[1] + "!</font></center></br>");It was quite entertaining, I've never even heard of some of these American holidays... what exactly happens on the Penguin Popcorn Parade? And what on earth is Petentine's Day? o.@

techno_race
03-02-2007, 01:43 AM
Actually, I made Penguin Popcorn Parade and Petentine's Day up.
ASPCA is indeed the equivalent of RSPCA. (ASPCA = The American Society for the Prevention of Cruelty to Animals.)
As you might guess, Martin Luther King, George Washington and Abraham Lincoln are some very famous American people...anything else?

I noticed you updated the humanMonth values. I meant to but never found time. :o
I noticed var holiday = holidays[(month + 1) + "/" + day] || [humanMonth + " " + day, ""];. Yikes!
I'm guessing that means that holiday's value is humanMonth and day's value unless month + 1 and day have the same value of an object in the holidays array. In that case, holiday's value equals the first value in the correct object and then the second value in the CSS class exclamation.

Twey
03-02-2007, 01:52 AM
Actually, I made Penguin Popcorn Parade and Petentine's Day up.Ahahaha, I should've guessed :D
I noticed var holiday = holidays[(month + 1) + "/" + day] || [humanMonth + " " + day, ""];. Yikes!
I'm guessing that means that holiday's value is humanMonth and day's value unless month + 1 and day have the same value of an object in the holidays array. In that case, holiday's value equals the first value in the correct object and then the second value in the CSS class exclamation.Yes. To break it down:Concatenate the month (plus one), a slash, and the date, so it's in the form '3/1' Get a value from holidays using that as the key If that value doesn't exist, or is false, empty, 0, or null, use the array [humanMonth + " " + day, ""] instead Assign the result to holiday.In Javascript, an or operation returns the first true value it encounters. So:
var a = false, b = 0, c = "Truthy string";
var d = a || b || c; // d is "Truthy string"
var e = a || null || c || b; // e is "Truthy string"
var f = b || true || c; // f is true

techno_race
03-02-2007, 02:25 AM
By the way, what does イギリス mean and in what language?

tech_support
03-02-2007, 05:42 AM
England, in Japanese.

(Why can't you write it in ENGLISH, Twey? :p)

Twey
03-02-2007, 02:52 PM
Because that would be boring :p

The other way the Japanese have of writing England is 英国, which, purely through phonetics, literally means "hero land." I pity Germans in Japan: they get to be 独逸人, "lonely lazy people" (独逸 is pronounced "doitsu" which is about as close to the German pronunciation of "Deutsch" as the Japanese syllabaries can get).

techno_race
03-02-2007, 10:44 PM
I see you changed it to 英国.

techno_race
03-04-2007, 05:57 PM
Why is EVERYTHING choking on

<marquee behavior="normal" direction="left">Welcome
to SGB Airport. Next shuttle
leaves
<script type="text/javascript">
var date = new Date();
var key = date.getMinutes();
var leaves;
var now = "no";

switch (key) {
case 0 :
leaves = "in 0 minutes";
now = "yes";
break;
case 1 :
leaves = "in 4 minutes";
break;
case 2 :
leaves = "in 3 minutes"
break;
case 3 :
leaves = "in 2 minutes"
break;
case 4 :
leaves = "in 1 minute"
break;
case 5 :
leaves = "in 0 minutes";
now = "yes";
break;
case 6 :
leaves = "in 4 minutes";
break;
case 7 :
leaves = "in 3 minutes"
break;
case 8 :
leaves = "in 2 minutes"
break;
case 9 :
leaves = "in 1 minute"
break;
case 10 :
leaves = "in 0 minutes";
now = "yes";
break;
case 11 :
leaves = "in 4 minutes";
break;
case 12 :
leaves = "in 3 minutes"
break;
case 13 :
leaves = "in 2 minutes"
break;
case 14 :
leaves = "in 1 minute"
break;
case 15 :
leaves = "in 0 minutes";
now = "yes";
break;
case 16 :
leaves = "in 4 minutes";
break;
case 17 :
leaves = "in 3 minutes"
break;
case 18 :
leaves = "in 2 minutes"
break;
case 19 :
leaves = "in 1 minute"
break;
case 20 :
leaves = "in 0 minutes";
now = "yes";
break;
case 21 :
leaves = "in 4 minutes";
break;
case 22 :
leaves = "in 3 minutes"
break;
case 23 :
leaves = "in 2 minutes"
break;
case 24 :
leaves = "in 1 minute"
break;
case 25 :
leaves = "in 0 minutes";
now = "yes";
break;
case 26 :
leaves = "in 4 minutes";
break;
case 27 :
leaves = "in 3 minutes"
break;
case 28 :
leaves = "in 2 minutes"
break;
case 29 :
leaves = "in 1 minute"
break;
case 30 :
leaves = "in 0 minutes";
now = "yes";
break;
case 31 :
leaves = "in 4 minutes";
break;
case 32 :
leaves = "in 3 minutes"
break;
case 33 :
leaves = "in 2 minutes"
break;
case 34 :
leaves = "in 1 minute"
break;
case 35 :
leaves = "in 0 minutes";
now = "yes";
break;
case 36 :
leaves = "in 4 minutes";
break;
case 37 :
leaves = "in 3 minutes"
break;
case 38 :
leaves = "in 2 minutes"
break;
case 39 :
leaves = "in 1 minute"
break;
case 40 :
leaves = "in 0 minutes";
now = "yes";
break;
case 41 :
leaves = "in 4 minutes";
break;
case 42 :
leaves = "in 3 minutes"
break;
case 43 :
leaves = "in 2 minutes"
break;
case 44 :
leaves = "in 1 minute"
break;
case 45 :
leaves = "in 0 minutes";
now = "yes";
break;
case 46 :
leaves = "in 4 minutes";
break;
case 47 :
leaves = "in 3 minutes"
break;
case 48 :
leaves = "in 2 minutes"
break;
case 49 :
leaves = "in 1 minute"
break;
case 50 :
leaves = "in 0 minutes";
now = "yes";
break;
case 51 :
leaves = "in 4 minutes";
break;
case 52 :
leaves = "in 3 minutes"
break;
case 53 :
leaves = "in 2 minutes"
break;
case 54 :
leaves = "in 1 minute"
break;
case 55 :
leaves = "in 0 minutes";
now = "yes";
break;
case 56 :
leaves = "in 4 minutes";
break;
case 57 :
leaves = "in 3 minutes"
break;
case 58 :
leaves = "in 2 minutes"
break;
case 59 :
leaves = "in 1 minute"
break;
}
if (now == "yes") {
window.location="shuttle.html"
}
else {
window.location="index.html"
}
document.write(leaves);
</script>.</marquee>

Twey
03-04-2007, 06:13 PM
<marquee behavior="normal" direction="left"><marquee> is a big no-no in web design :)
var now = "no";Use a boolean value, or even just check whether leaves is 0.
switch (key) {Dear gods! You're raping switch!
document.write(leaves);This will never be reached -- the browser will be directed to either shuttle.html or index.html, but either way it happens before this.

Factor in all of the above, and you can write that hideously huge switch statement in two lines:
var leaves = (function(x) { var v = x &#37; 5; return (v === 0 ? 0 : 5) - v; })((new Date()).getMinutes());

window.location.href = (leaves === 0 ? "shuttle.html" : "index.html");If you want to write that time rather than redirect to index.html, you can:
var leaves = (function(x) { var v = x % 5; return (v === 0 ? 0 : 5) - v; })((new Date()).getMinutes());

if(leaves === 0)
window.location.href = "shuttle.html";
else
document.write("in " + leaves + " minute" + (leaves === 1 ? "" : "s"));

mburt
03-04-2007, 06:16 PM
Lol... raping? Not raping, but definitely over-using. In fact, I never use switch. Arrays are much easier to use.

techno_race
03-04-2007, 06:18 PM
Huh?

var leaves = (function(x) { var v = x &#37; 5; return (v === 0 ? 0 : 5) - v; })((new Date()).getMinutes());

window.location.href = (leaves === 0 ? "shuttle.html" : "index.html");?

Is there any way to make that update every minute...or does it already? And what was the actual problem with the first one?

techno_race
03-04-2007, 06:19 PM
I never learned what an array was, all I learned was if...else and switch.

techno_race
03-04-2007, 06:21 PM
And I take it that if it's 10:21, it writes '4,' not 'in 4 minutes.' Is that right?

techno_race
03-04-2007, 06:25 PM
Aye. Everything was thinking that I wanted the page to refrech the page every nanosecond :p. Does that refresh every minute? Or can I even do it in the script? Do I need the <meta http-equiv="refresh"> tag?

Twey
03-04-2007, 06:32 PM
var leaves = (function(x) { var v = x &#37; 5; return (v === 0 ? 0 : 5) - v; })((new Date()).getMinutes());Sorry, that's kind of advanced... it creates an anonymous function (one without a name), then calls it with the current minutes as an argument. It's equivalent to:
function f(x) {
var v = x % 5;
if(v === 0)
return v;
else
return 5 - v;
}

var d = new Date();
var leaves = f(d.getMinutes());... but obviously much shorter. :p
window.location.href = (leaves === 0 ? "shuttle.html" : "index.html");This is an example of the tertiary operator.
var a = b ? c : d;is equivalent to:
var a;
if(b)
a = c;
else
a = d;
Is there any way to make that update every minute...or does it already?No, it doesn't. Since the user is redirected immediately, there's no point... oh. Now I see what you were attempting with location.href = "index.html". Don't do this. Instead, try something like:
<p>Welcome to SGB Airport. Next shuttle leaves in <span id="nextshuttle">?</span>.</p>

<script type="text/javascript">
var leaves = (function() { var v = (new Date()).getMinutes() % 5; return (v === 0 ? 0 : 5) - v; })();

function updateMinutes() {
var l = leaves();
document.getElementById("nextshuttle").firstChild.nodeValue = l + (l === 1 ? " minute" : " minutes");
}
setInterval(updateMinutes, 60000);
</script>
I never learned what an array was, all I learned was if...else and switch.Arrays are vital in Javascript.
And I take it that if it's 10:21, it writes '4,' not 'in 4 minutes.' Is that right?No. What lead you to that conclusion?
Everything was thinking that I wanted the page to refrech the page every nanosecond . Does that refresh every minute? Or can I even do it in the script? Do I need the <meta http-equiv="refresh"> tag?Ugh! The original doesn't, but the one above will update the time every minute. You don't need <meta>.

techno_race
03-04-2007, 06:39 PM
Yeah. I think the cause of the refreshing was

else {
window.location="index.html"
}
It should have been
else {
}

Twey
03-04-2007, 06:41 PM
Yes, I said this. It should, in fact, have been:

techno_race
03-04-2007, 06:43 PM
Except now I get 'Welcome to SGB Airport. Next shuttle leaves in ?. ..'

Twey
03-04-2007, 06:50 PM
Not if you wait a minute :) You want to call it once first:
<p>Welcome to SGB Airport. Next shuttle leaves in <span id="nextshuttle">?</span>.</p>

<script type="text/javascript">
var leaves = (function() { var v = (new Date()).getMinutes() &#37; 5; return (v === 0 ? 0 : 5) - v; })();

function updateMinutes() {
var l = leaves();
document.getElementById("nextshuttle").firstChild.nodeValue = l + (l === 1 ? " minute" : " minutes");
}

setInterval(updateMinutes, 60000);
updateMinutes();
</script>

techno_race
03-04-2007, 06:50 PM
Wait. I think you should see this:
http://img238.imageshack.us/img238/6162/leavescc3.th.gif (http://img238.imageshack.us/my.php?image=leavescc3.gif)
I opened it in Firefox w/ Firebug ang got this message.

Twey
03-04-2007, 07:53 PM
... what message?

ImageShack doesn't like me.

techno_race
03-04-2007, 07:54 PM
And it throws 4 more of those every minute.

techno_race
03-04-2007, 07:56 PM
http://img238.imageshack.us/img238/6162/leavescc3.gif

techno_race
03-04-2007, 07:57 PM
see it now?

Twey
03-04-2007, 07:59 PM
No:
An error occurred while loading http://img238.imageshack.us/my.php?image=leavescc3.gif:

Connection to host img238.imageshack.us is broken.Try hosting it somewhere else.

techno_race
03-04-2007, 08:00 PM
Heh heh heh. 'leaves() is not a function.'

techno_race
03-04-2007, 08:01 PM
Shouldn't [CODE] be [QUOTE] in that case?

Twey
03-04-2007, 08:14 PM
Ah, sorry, I left some brackets in that I shouldn't have:
<p>Welcome to SGB Airport. Next shuttle leaves in <span id="nextshuttle">?</span>.</p>

<script type="text/javascript">
var leaves = (function() { var v = (new Date()).getMinutes() &#37; 5; return (v === 0 ? 0 : 5) - v; });

function updateMinutes() {
var l = leaves();
document.getElementById("nextshuttle").firstChild.nodeValue = l + (l === 1 ? " minute" : " minutes");
}

setInterval(updateMinutes, 60000);
updateMinutes();
</script>There're no semantics involved, they both get expanded to <div>s anyway.

techno_race
03-04-2007, 08:25 PM
Two problems - it says 'Next shuttle leaves in _ minute(s). .,' and when it says '0 minutes' the page doesn't change location to shuttle.htm. For the first problem, might I consider removing '.' from after '</script>?'
For the second, might I need:

if (l == "0 minutes") {
window.location="shuttle.htm"
} somewhere?

Twey
03-04-2007, 09:07 PM
Argh, I'm losing it -- first my English, now my Javascript is going :(
<p>Welcome to SGB Airport. Next shuttle leaves in <span id="nextshuttle">?</span>.</p>

<script type="text/javascript">
var leaves = (function() { var v = (new Date()).getMinutes() &#37; 5; return (v === 0 ? 0 : 5) - v; });

function updateMinutes() {
var l = leaves();
document.getElementById("nextshuttle").firstChild.nodeValue = l + (l === 1 ? " minute" : " minutes");
if(!l) window.location.href = "shuttle.html";
}

setInterval(updateMinutes, 60000);
updateMinutes();
</script>There should be no . after the script -- the script should not be in a text element. It should be exactly as I posted it.

techno_race
03-04-2007, 09:11 PM
Oops! It was, I forgot! therefore, <span>?

Twey
03-04-2007, 09:13 PM
What about <span>?

techno_race
03-04-2007, 10:35 PM
Hahaha! The '.' after the span. I solved it myself, I actually had . . after it!

techno_race
03-04-2007, 10:35 PM
Please note, anyone else is welcome to post JavaScripts here...

techno_race
03-08-2007, 01:59 AM
I can't figure out
<?xml version="1.0" encoding="iso-8859-1"?>
<!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">
<head>
<title>Time:</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript">
function displayText() {
var text = document.getElementById("myText");
text.style.visibility=(document.myForm.options.checked) ? "visible" : "hidden";
}

function displayDay() {
var day = document.getElementById("showDay");
day.style.visibility=(document.myForm2.dy.checked) ? "visible" : "hidden";
}

function displayMonth() {
var month = document.getElementById("showMonth");
month.style.visibility=(document.myForm2.mon.checked) ? "visible" : "hidden";
}

function displayDate() {
var date = document.getElementById("showDate");
date.style.visibility=(document.myForm2.dt.checked) ? "visible" : "hidden";
}

function displayYear() {
var year = document.getElementById("showYear");
year.style.visibility=(document.myForm2.yr.checked) ? "visible" : "hidden";
}

function displayHour() {
var hour = document.getElementById("showHour");
hour.style.visibility=(document.myForm2.hr.checked) ? "visible" : "hidden";
}

function displayMinute() {
var minute = document.getElementById("showMinute");
minute.style.visibility=(document.myForm2.mn.checked) ? "visible" : "hidden";
}

function displaySecond() {
var second = document.getElementById("showSecond");
second.style.visibility=(document.myForm2.sec.checked) ? "visible" : "hidden";
}

function displayMillisecond() {
var millisecond = document.getElementById("showMillisecond");
millisecond.style.visibility=(document.myForm2.ms.checked) ? "visible" : "hidden";
}
</script>
</head>

<body>
<span id="showDay">Sunday, </span><span id="showMonth">January </span><span id="showDate">1, </span><span id="showYear">0 </span><span id="showHour">12</span><span id="showMinute">:00</span><span id="showSecond">:00</span><span id="showMillisecond">.0</span><br />
<form id="myForm"><input name="options" type="checkbox" onClick="displayText();" />Options<br /></form>
<div id="myText"><form id="myForm2"><input name="dy" type="checkbox" onClick="displayDay();" />Day<br />
<input name="mon" type="checkbox" onClick="displayMonth();" />Month<br />
<input name="dt" type="checkbox" onClick="displayDate();" />Date<br />
<input name="yr" type="checkbox" onClick="displayYear();" />Year<br />
<input name="hr" type="checkbox" onClick="displayHour();" />Hour<br />
<input name="mn" type="checkbox" onClick="displayMinute();" />Minute<br />
<input name="sec" type="checkbox" onClick="displaySecond();" />Second<br />
<input name="ms" type="checkbox" onClick="displayMillisecond();" />Millisecond</form></div>
<script type="text/javascript">
var get = new Date();
var oldday = get.getDay();
var newday = [
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"
][oldday];

var oldmonth = get.getMonth();
var newmonth = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
][oldmonth];

var getdate = get.getDate();
var getyear = get.getFullYear();
var oldhour = get.getHours();
var newhour;

if (oldhour >= 12) {
newhour = oldhour -= 12;
}
else {
newhour = oldhour;
}

var oldminute = get.getMinutes();
var newminute;

if (oldminute <= 10) {
newminute = "0" + oldminute;
}
else {
newminute = oldminute;
}

var getsecond = get.getSeconds();
var getmillisecond = get.getMilliseconds();

function update() {
var writeday = newday;
document.getElementById("showDay").firstChild.nodeValue = writeday;
var writemonth = newmonth;
document.getElementById("showMonth").firstChild.nodeValue = writemonth;
var writedate = getdate;
document.getElementById("showDate").firstChild.nodeValue = writedate;
var writeyear = getyear;
document.getElementById("showYear").firstChild.nodeValue = writeyear;
var writehour = newhour;
document.getElementById("showHour").firstChild.nodeValue = writehour;
var writeminute = newminute;
document.getElementById("showMinute").firstChild.nodeValue = writeminute;
var writesecond = getsecond;
document.getElementById("showSecond").firstChild.nodeValue = writesecond;
var writemillisecond = getmillisecond;
document.getElementById("showMillisecond").firstChild.nodeValue = writemillisecond;
}

setInterval(update, 1);
update();

</script>
</body>
</html>

It doesn't seem to work. I don't know how to make everything but Options initially checked, how to make it refresh every millesecond, and how to make the checkboxes work.
Edit: And how to make it say Wednesday, March 7, 2007 5:54:11.601 instead of WednesdayMarch7200755411601.

tech_support
03-09-2007, 05:51 AM
AJAX...I think that's related to PHP.

Nope. AJAX sends data from one page to another without refreshing the page.

techno_race
03-09-2007, 04:22 PM
As I was saying, I need help with

<?xml version="1.0" encoding="iso-8859-1"?>
<!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">
<head>
<title>Time:</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript">
function displayText() {
var text = document.getElementById("myText");
text.style.visibility=(document.myForm.options.checked) ? "visible" : "hidden";
}

function displayDay() {
var day = document.getElementById("showDay");
day.style.visibility=(document.myForm2.dy.checked) ? "visible" : "hidden";
}

function displayMonth() {
var month = document.getElementById("showMonth");
month.style.visibility=(document.myForm2.mon.checked) ? "visible" : "hidden";
}

function displayDate() {
var date = document.getElementById("showDate");
date.style.visibility=(document.myForm2.dt.checked) ? "visible" : "hidden";
}

function displayYear() {
var year = document.getElementById("showYear");
year.style.visibility=(document.myForm2.yr.checked) ? "visible" : "hidden";
}

function displayHour() {
var hour = document.getElementById("showHour");
hour.style.visibility=(document.myForm2.hr.checked) ? "visible" : "hidden";
}

function displayMinute() {
var minute = document.getElementById("showMinute");
minute.style.visibility=(document.myForm2.mn.checked) ? "visible" : "hidden";
}

function displaySecond() {
var second = document.getElementById("showSecond");
second.style.visibility=(document.myForm2.sec.checked) ? "visible" : "hidden";
}

function displayMillisecond() {
var millisecond = document.getElementById("showMillisecond");
millisecond.style.visibility=(document.myForm2.ms.checked) ? "visible" : "hidden";
}
</script>
</head>

<body>
<span id="showDay">Sunday, </span><span id="showMonth">January </span><span id="showDate">1, </span><span id="showYear">0 </span><span id="showHour">12</span><span id="showMinute">:00</span><span id="showSecond">:00</span><span id="showMillisecond">.0</span><br />
<form id="myForm"><input name="options" type="checkbox" onClick="displayText();" />Options<br /></form>
<div id="myText"><form id="myForm2"><input name="dy" type="checkbox" onClick="displayDay();" />Day<br />
<input name="mon" type="checkbox" onClick="displayMonth();" />Month<br />
<input name="dt" type="checkbox" onClick="displayDate();" />Date<br />
<input name="yr" type="checkbox" onClick="displayYear();" />Year<br />
<input name="hr" type="checkbox" onClick="displayHour();" />Hour<br />
<input name="mn" type="checkbox" onClick="displayMinute();" />Minute<br />
<input name="sec" type="checkbox" onClick="displaySecond();" />Second<br />
<input name="ms" type="checkbox" onClick="displayMillisecond();" />Millisecond</form></div>
<script type="text/javascript">
var get = new Date();
var oldday = get.getDay();
var newday = [
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"
][oldday];

var oldmonth = get.getMonth();
var newmonth = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
][oldmonth];

var getdate = get.getDate();
var getyear = get.getFullYear();
var oldhour = get.getHours();
var newhour;

if (oldhour >= 12) {
newhour = oldhour -= 12;
}
else {
newhour = oldhour;
}

var oldminute = get.getMinutes();
var newminute;

if (oldminute <= 10) {
newminute = "0" + oldminute;
}
else {
newminute = oldminute;
}

var getsecond = get.getSeconds();
var getmillisecond = get.getMilliseconds();

function update() {
var writeday = newday;
document.getElementById("showDay").firstChild.nodeValue = writeday;
var writemonth = newmonth;
document.getElementById("showMonth").firstChild.nodeValue = writemonth;
var writedate = getdate;
document.getElementById("showDate").firstChild.nodeValue = writedate;
var writeyear = getyear;
document.getElementById("showYear").firstChild.nodeValue = writeyear;
var writehour = newhour;
document.getElementById("showHour").firstChild.nodeValue = writehour;
var writeminute = newminute;
document.getElementById("showMinute").firstChild.nodeValue = writeminute;
var writesecond = getsecond;
document.getElementById("showSecond").firstChild.nodeValue = writesecond;
var writemillisecond = getmillisecond;
document.getElementById("showMillisecond").firstChild.nodeValue = writemillisecond;
}

setInterval(update, 1);
update();

</script>
</body>
</html>

techno_race
03-15-2007, 02:23 AM
Anyone?

techno_race
03-18-2007, 05:31 PM
Hello?

Twey
03-18-2007, 10:25 PM
Demo page please?

techno_race
03-18-2007, 10:47 PM
/--Attachments:----------\
'878__________'
'_______________________'
'_______________________'
\______________________/

Edit: sorry about the edits.

techno_race
03-20-2007, 01:39 AM
That was supposed to be funny.

techno_race
03-24-2007, 12:00 AM
PLEASE!!!!

mburt
04-07-2007, 06:40 PM
Can we see the entire script?

techno_race
04-07-2007, 06:46 PM
Huh? The whole thing's not in 878? What's it missing?

mburt
04-07-2007, 06:47 PM
<?xml version="1.0" encoding="iso-8859-1"?>
<!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">
<head>
<title>Time:</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript">
function displayText() {
var text = document.getElementById("myText");
text.style.visibility=(document.forms['myForm'].options.checked) ? "visible" : "hidden";
}

function displayDay() {
var day = document.getElementById("showDay");
day.style.visibility=(document.getElementById('dy').checked) ? "visible" : "hidden";
}

function displayMonth() {
var month = document.getElementById("showMonth");
month.style.visibility=(document.getElementById("mon").checked) ? "visible" : "hidden";
}

function displayDate() {
var date = document.getElementById("showDate");
date.style.visibility=(document.getElementById('dt').checked) ? "visible" : "hidden";
}

function displayYear() {
var year = document.getElementById("showYear");
year.style.visibility=(document.getElementById('yr').checked) ? "visible" : "hidden";
}

function displayHour() {
var hour = document.getElementById("showHour");
hour.style.visibility=(document.getElementById('hr').checked) ? "visible" : "hidden";
}

function displayMinute() {
var minute = document.getElementById("showMinute");
minute.style.visibility=(document.getElementById('mn').checked) ? "visible" : "hidden";
}

function displaySecond() {
var second = document.getElementById("showSecond");
second.style.visibility=(document.getElementById('sec').checked) ? "visible" : "hidden";
}

function displayMillisecond() {
var millisecond = document.getElementById("showMillisecond");
millisecond.style.visibility=(document.getElementById('ms.checked').checked) ? "visible" : "hidden";
}
</script>
</head>

<body>
<span id="showDay">Sunday, </span><span id="showMonth">January </span><span id="showDate">1, </span><span id="showYear">0 </span><span id="showHour">12</span><span id="showMinute">:00</span><span id="showSecond">:00</span><span id="showMillisecond">.0</span><br />
<form id="myForm"><input name="options" type="checkbox" onClick="displayText();" />Options<br /></form>
<div id="myText"><form id="myForm2"><input name="dy" type="checkbox" onClick="displayDay();" />Day<br />
<input name="mon" type="checkbox" onClick="displayMonth();" />Month<br />
<input name="dt" type="checkbox" onClick="displayDate();" />Date<br />
<input name="yr" type="checkbox" onClick="displayYear();" />Year<br />
<input name="hr" type="checkbox" onClick="displayHour();" />Hour<br />
<input name="mn" type="checkbox" onClick="displayMinute();" />Minute<br />
<input name="sec" type="checkbox" onClick="displaySecond();" />Second<br />
<input name="ms" type="checkbox" onClick="displayMillisecond();" />Millisecond</form></div>
<script type="text/javascript">
var get = new Date();
var oldday = get.getDay();
var newday = [
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"
][oldday];

var oldmonth = get.getMonth();
var newmonth = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
][oldmonth];

var getdate = get.getDate();
var getyear = get.getFullYear();
var oldhour = get.getHours();
var newhour;

if (oldhour >= 12) {
newhour = oldhour -= 12;
}
else {
newhour = oldhour;
}

var oldminute = get.getMinutes();
var newminute;

if (oldminute <= 10) {
newminute = "0" + oldminute;
}
else {
newminute = oldminute;
}

var getsecond = get.getSeconds();
var getmillisecond = get.getMilliseconds();

function update() {
var writeday = newday;
document.getElementById("showDay").firstChild.nodeValue = writeday;
var writemonth = newmonth;
document.getElementById("showMonth").firstChild.nodeValue = writemonth;
var writedate = getdate;
document.getElementById("showDate").firstChild.nodeValue = writedate;
var writeyear = getyear;
document.getElementById("showYear").firstChild.nodeValue = writeyear;
var writehour = newhour;
document.getElementById("showHour").firstChild.nodeValue = writehour;
var writeminute = newminute;
document.getElementById("showMinute").firstChild.nodeValue = writeminute;
var writesecond = getsecond;
document.getElementById("showSecond").firstChild.nodeValue = writesecond;
var writemillisecond = getmillisecond;
document.getElementById("showMillisecond").firstChild.nodeValue = writemillisecond;
}

setInterval(update, 1);
update();

</script>
</body>
</html>

techno_race
04-07-2007, 06:51 PM
So, what was the problem?

mburt
04-07-2007, 07:39 PM
You referenced each item with document.form, when they weren't even inside a form element. You had to use document.getElementById().

techno_race
05-11-2007, 04:32 PM
Yes they were. The milliseconds button doesn't work and it doesn't have the date and time.

techno_race
06-20-2008, 07:08 PM
Yeah, yeah, I know, 13 months, but...

var width = 100;
var unit = "percent";
// 'width' is the width, in pixels or a percentage of the entire width of the browser window.
// 'unit' is the unit used in width -- its possible values are:
// pixels
// percent

var align = "center";
// The alignment of the rule. Possible values are:
// left
// center
// right
// Center is recommended to best simulate the XP startmenu dividers.

/*
Windows XP Horizontal Rule
by techno_race
http://www.dynamicdrive.com
*/

var fail = "Error, please check coding.";
var style1 = 'bgcolor="#D3D3C8" style="background-color: #D3D3C8;"';
var style2 = 'bgcolor="#FEFEFE" style="background-color: #FEFEFE;"';

if (unit == "pixels") {
var prepixelsnc = unit - 33;
if (prepixelsnc <= 0) {
var pixelsnc = 1;
}
if (prepixels > 0) {
var pixelsnc = prepixelsnc;
}
var fullnc = pixelsnc + 33;
}

if (align == "center") {
if (unit == pixels) {
var prepixels = unit - 66;
if (prepixels <= 0) {
var pixels = 1;
}
if (prepixels > 0) {
var pixels = prepixels;
}
var full = pixels + 66;
document.write('<table align="center" border="0" cellspacing="0" cellpadding="0"><tr><td width="33" height="1"><img src="lt.png" width="33" height="1"></td><td width="' + pixels + '" height="1" ' + style1 + '></td><td width="33" height="1"><img src="rt.png" width="33" height="1"></td></tr><tr><td width="33" height="1"><img src="lb.png" width="33" height="1"></td><td width="' + pixels + '" height="1" ' + style2 + '></td><td width="33" height="1"><img src="rb.png" width="33" height="1"></td></tr></table>');
}
if (unit == "percent") {
document.write('<table align="center" width="' + unit + '%" border="0" cellspacing="0" cellpadding="0"><tr><td width="33" height="1"><img src="lt.png" width="33" height="1"></td><td height="1" ' + style2 + '></td><td width="33" height="1"><img src="rt.png" width="33" height="1"></td></tr><tr><td width="33" height="1"><img src="lb.png" width="33" height="1"></td><td height="1" ' + style2 + '></td><td width="33" height="1"><img src="rb.png" width="33" height="1"></td></tr></table>');
}
}
if (align == "left") {
if (unit == "pixels") {
document.write('<table align="left" width="' + fullnc + '" border="0" cellspacing="0" cellpadding="0"><tr><td width="' + pixelsnc + '" height="1" ' + style1 + '></td><td width="33" height="1"><img src="rt.png" width="33" height="1"></td></tr><tr><td width="' + pixels + '" height="1" ' + style2 + '></td><td width="33" height="1"><img src="rb.png" width="33" height="1"></td></tr></table>');
}
if (unit == "percent") {
document.write('<table align="left" width="' + unit + '%" border="0" cellspacing="0" cellpadding="0"><tr><td height="1" ' + style1 + '></td><td width="33" height="1"><img src="rt.png" width="33" height="1"></td></tr><tr><td height="1" ' + style2 + '></td><td width="33" height="1"><img src="rb.png" width="33" height="1"></td></tr></table>');
}
}
if (align == "right") {
if (unit == "pixels") {
document.write('<table align="right" width="' + fullnc + '" border="0" cellspacing="0" cellpadding="0"><tr><td width="33" height="1"><img src="lt.png" width="33" height="1"></td><td width="' + pixelsnc + '" height="1" ' + style1 + '></td></tr><tr><td width="33" height="1"><img src="lb.png" width="33" height="1"></td><td width="' + pixels + '" height="1" ' + style2 + '></td></tr></table>');
}
if (unit == "percent") {
document.write('<table align="right" width="' + unit + '%" border="0" cellspacing="0" cellpadding="0"><tr><td width="33" height="1"><img src="lt.png" width="33" height="1"></td><td height="1" ' + style1 + '></td></tr><tr><td width="33" height="1"><img src="lb.png" width="33" height="1"></td><td height="1" ' + style2 + '></td></tr></table>');
}
}
else {
document.write(fail);
}
This is a bit edited. The entire script is in the attached archive. Can it also be used multiple times on one page?

techno_race
06-22-2008, 02:16 PM
Nope. AJAX sends data from one page to another without refreshing the page.
I can't believe I never replied to that. So, it is related to PHP, it sends data from one page to the other without refreshing the page, and PHP sends data from one page to the other with refreshing the page.

tech_support
06-23-2008, 08:20 AM
Could be done with any other language, like ASP.net
....and why reply now? A bit late?