...

View Full Version : Using SRC="Javascript program"



Ann-Marie
12-25-2011, 09:32 AM
Why doesn't this work? Both files are in the same folder. I'm sure I've done this many times before???

HTML File "Test.htm" :-


<html>
<head>
<script type="text/javascript" src="Test.js"></script>
</head>
<body>
<h1>My First Web Page</h1>
<p id="demo">This is a paragraph.</p>
<button type="button" onclick="displayDate()">Display Date</button>
</body>
</html>


javascript File "Test.js" :-


function displayDate(){
document.getElementById("demo").innerHTML=Date();
}

Philip M
12-25-2011, 10:10 AM
document.getElementById("demo").innerHTML= new Date();


All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

Ann-Marie
12-25-2011, 10:18 AM
Thanks Philip, that was not the problem.

The problem is somewhat obscure. There are no apparent errors in the programs. If you copy past the program in your own computer it will not run.

The problem is that there are some invisible UTF-16 characters embedded in the program that I can't get to show on my editor but you can see evidence if you look at the browser Error Console when you run it.

Copy/paste to Notepad and re-copy/paste to the htm file and now it will work.

Philip M
12-25-2011, 10:22 AM
Thanks Philip, that was not the problem.

There are no apparent errors in the programs. If you copy past the program in your own computer it will not run.



It works for me when I correct the error in your program which is indeed quite apparant.

Ann-Marie
12-25-2011, 10:41 AM
OK the program I was using for testing is a copy paste out of the w3schools.com tutorials modified to use the SRC= function.

I introduced a problem by selecting all of an old file and pasting the test file over it. Selecting all the old file DID NOT select the invisible UTF-16 characters so they got left behind.

The original works fine in their tutorial and after removing the UTF-16 characters it works for me without your suggestion.

My editor is having serious problems with UTF-16 characters so I think I will remove ALL the UTF-16 text from the htm file and save them separately in a script file dedicated to the text look-up.

I appreciate your suggestion and I will see if it should be included for "correct" scripting.

Philip M
12-25-2011, 11:00 AM
It is always amusing when youngsters attempting their "first web page" try to teach their grandmothers to suck eggs. :p

You need to note that JavaScript Date objects can only be instantiated by calling JavaScript Date as a constructor: calling it as a regular function (i.e. without the new operator) will return a string rather than a Date object; unlike other JavaScript object types, JavaScript Date objects have no literal syntax.


<script type="text/javascript">

var d= new Date();
alert (typeof d); // object
document.write(d);
var d = Date();
alert (typeof d); // string
document.write (d);

</script>

So while Date() works to display the current date in this simple example it does not return a Date object which can be manipluated. OK?



<script type = "text/javascript">

var myDate=new Date();
myDate.setDate(myDate.getDate()+5);
alert (myDate); // current date plus 5 days

var myDate=Date();
myDate.setDate(myDate.getDate()+5);
alert (myDate); // error
}
</script>

I would be interested to se a link to the w3schools tutorial script you say you have copied - I do not find it.

Ann-Marie
12-25-2011, 03:06 PM
LOL thanks for the compliment Philip. I've been a computer programmer since before you were born.

It was modified from
http://w3schools.com/js/tryit.asp?filename=tryjs_events

Philip M
12-26-2011, 04:17 PM
LOL thanks for the compliment Philip. I've been a computer programmer since before you were born.

It was modified from
http://w3schools.com/js/tryit.asp?filename=tryjs_events

In that case you must be very, very old!!! Were there any computer programmers before I was born????


Bessie Braddock to Winston Churchill - "Sir, you are disgustingly drunk".
Winston Churchill - "Madam, you are disgustingly ugly. But I will be sober in the morning".

Ann-Marie
12-26-2011, 04:57 PM
Oh yes, I started on UNIVAC III in 1959.

Philip M
12-26-2011, 05:01 PM
Oh yes, I started on UNIVAC III in 1959.


That was not befoe I was born! But perhaps it was before you were born. :D:D

Wikipedia informs me Sperry Rand began shipment in June 1962 and produced 96 UNIVAC III systems so you were very precocious to be working on one in 1959. If you were 19 then you must be, er, 71 now.

Ann-Marie
12-26-2011, 05:06 PM
No, I was born in 1939. UNIVAC III had just been installed in the University of NSW in Australia. It was my last year at the University and I was in their very first assembly language course. I swear by the end of the year I knew more about programming it than the lecturer. Those were the days of 80 column input/output cards, 3 hours each morning finding and replacing vacuum tubes that had died over night, 8 bit ultrasonic mercury delay lines for RAM. Yes I'm a novice in javascript but I've been an assembly language programmer for over 50 years.

Philip M
12-26-2011, 05:08 PM
No, I was born in 1939. UNIVAC III had just been installed in the University of NSW in Australia. It was my last year at the University and I was in their very first assembly language course. I swear by the end of the year I knew more about programming it than the lecturer. Those were the days of 80 column input/output cards, 3 hours each morning finding and replacing vacuum tubes that had died over night, 8 bit ultrasonic mercury delay lines for RAM. Yes I'm a novice in javascript but I've been an assembly language programmer for over 50 years.

I take my hat off to you! I did not start programming (in ALGOL) until 1965.

Old Pedant
12-27-2011, 05:04 AM
Boy, you both make me feel like a real novice!

The first time I wrote a computer program, I did my roommate's Fortran II homework for him in 1964, but that was only one program so I don't think it counts. I didn't really start programming for real until 1969 when I got access to a time sharing computer that had BASIC, Fortran, and PL/I on it. My first "assembly language" was on a programmable calculator (don't even remember who made it) that used punch cards, but you had to hand-punch the cards (they were pre-perforated chads) with a little metal stylus. Each instuction took one column on the card and was given as a pair of hexadecimal numbers (so there were 8 "chads" per column plus 1 you could punch to indicated to skip the column because you had goofed).

The first computer I really had "hands on" was an IBM 360/75 in 1971.

However, I will lay claim to having written the first BASIC interpreter for a microprocessor, which I did in 1972/73. (A 4-bit Rockwell PPS-4, if it matters.) I haven't met anybody yet who can claim an earlier date.

rnd me
12-27-2011, 06:26 AM
i started learning in 2007.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum