Someone dropped a job into my lap

H

Helmut Giese

Hello out there,
I am a rather experienced C programmer. However, today I got a
javascript assignment because someone left (something like: "You're a
great programmer - you'll handle this.") and I never have done any web
stuff before. Oh, and it's due within 2 weeks of course :(

Having had a first look at javascript I noted some familiarities with
C, but there also seems to be a lot of pre-defined stuff (like
'document') with certain properties / functions, which is a bit
confusing.

I have listed some basic questions below and I am hoping someone will
be able to provide some links ot other information answering those.

1) What is the current version of javascript which is supported by the
current browsers (or is this a no-issue)?

2) A reference of pre-defined objects and their properties /
functions.

3) How do you debug javascript? If you make an error, wrong HTML might
show up (this could give you a clue) but also nothing might show up at
all - what do you do then? Stare at the code?

4) Libraries / collection of often used functions (handling of strings
and dates, numeric stuff, etc.)

5) A side note: Is it possible in javascript to create variable names
at runtime and access them? Something like (e.g. iterating over input
fields)
for (i=0; i< 10; ++i) {
currField = <construct name of input field i here, e.g. inp0>
currField.value = ...
}

Any answers to the above questions or further helpful information will
be greatly apprieciated.
Best regards
Helmut Giese
 
E

Erwin Moller

Helmut said:
Hello out there,
I am a rather experienced C programmer. However, today I got a
javascript assignment because someone left (something like: "You're a
great programmer - you'll handle this.") and I never have done any web
stuff before. Oh, and it's due within 2 weeks of course :(

Hi Helmut,

Get a good book. :)
I'll try to answer a few questions, but a good book is what you need.
A good book to learn Javascript itself is:
Javascript, the definite guide by O'Reilly

If you should focus on HTML, Cascading Style Sheets, adn Document Object
Model (DOM), and want to use Javascript to manipulate pages/layout, I would
advise the book:
Dynamic HTML, the definity guide, also by O'Reilly.

Having had a first look at javascript I noted some familiarities with
C, but there also seems to be a lot of pre-defined stuff (like
'document') with certain properties / functions, which is a bit
confusing.

Yes, that are objects that represent something in a browser.
You'll see things like window, document, form, images, etc.

Javascript is an object oriented language with a lot of build in objects you
can use to manipulate pages.


I have listed some basic questions below and I am hoping someone will
be able to provide some links ot other information answering those.

1) What is the current version of javascript which is supported by the
current browsers (or is this a no-issue)?

I would like to pass this question to somebody else.
Javascript is and is not standarised.
Yes, ECMA (google for it) has defined a set of standards for javascript,
which are to a certain degree implemented in browsers, depending on the
browser/vendor, etc.

My approach is always: Code in Mozilla / Firefox, and test on IE on windows.
Always test on playforms/browsers you want to support.

The way javascript interacts with DOM, is different for IE and Mozilla.
They have a certain set of 'common functionality'.
2) A reference of pre-defined objects and their properties /
functions.

Depends on the browser.
If you get a good book, you will find all predifined objects listed.
I would advise you to read the second book above (Dynamic HTML) for a
comprehensive list of all objects and their methods, including the browsers
that support it.

3) How do you debug javascript? If you make an error, wrong HTML might
show up (this could give you a clue) but also nothing might show up at
all - what do you do then? Stare at the code?

Use Mozilla/Firefox: You can find a menu Tools -> Webdevelopment->Javascript
console.
When an error occurs, it will be listed there with relevant errormessages.

I also make entensive use of alert() or document.write() when debugging
scripts, just to output variables the old-fashioned way.

If you want a real Javascript debugger, check the FAQ, posted on a regular
basis in this newsgroup. (The one under your posting in my newsreader. :)

Before I forget: Read that FAQ: It contains answers to a zillion question
you might have.

4) Libraries / collection of often used functions (handling of strings
and dates, numeric stuff, etc.)

Zillions. Some of good quality, some suck.
The FAQ also contains some relevant links for that.

My advise would be to first code stuff yourself before using libs, so you
know what is going on and can trace bugs yourself.
5) A side note: Is it possible in javascript to create variable names
at runtime and access them? Something like (e.g. iterating over input
fields)
for (i=0; i< 10; ++i) {
currField = <construct name of input field i here, e.g. inp0>
currField.value = ...
}

Yes, you can add all kind of formelements to a HTML-page dynamically.
This is a little more complicated than replacing an image.
(I always prefer doing stuff like that serverside.)
Any answers to the above questions or further helpful information will
be greatly apprieciated.
Best regards
Helmut Giese


Well, I hope I said a few sensible things. :)

Good luck.
2 weeks are gone very fast. :-/

Regards,
Erwin Moller
 
B

Baconbutty

Having had a first look at javascript I noted some familiarities with

Only in syntax. Otherwise I believe it is fundamentally different.
, but there also seems to be a lot of pre-defined stuff (like
'document') with certain properties / functions, which is a bit
confusing.

The "pre-defined stuff" is largely not Javascript, but objects exposed
to Javascript by the web browser.

When used in the web browser, there is a binding between Javascript and
the web browser. Look up terms such as browser and document object
models.
1) What is the current version of javascript which is supported by the
current browsers (or is this a no-issue)?

There is no on controller of the Javascript language. Created by
Brendan Eich for the Netscape browser, it was subsequently standardised
in the ECMA standard.

Microsoft's implementation is called JScript, and is at 5.6.
Microsoft have also created JScript.NET, but this is not available to
use in the browser.

Firefox is derived from Netscape, and is at 1.5 (or soon to be 1.6 I
believe, as there as some recent additions), and Firefox is now also
implementing an extension giving native XML support within Javascipt.
There is also a draft 2.0 floating about, which proposes to implement
class based OOP, in addition to Javascript's prototype based OOP.
2) A reference of pre-defined objects and their properties /
functions.

In terms of native Javascript data types and objects
(Object,Function,Array,String,Number etc..) and their methods, visit
the Mozilla web site (Javascript), or the Microsoft MSDN web site
(JScript). Alternatively, read the ECMA standard.

In terms of the browser objects which are exposed to Javascript, there
are a multitude of references on the internet. The www.w3c.org is the
home of the standards for HTML, XML, DOM, CSS etc. But each browser
varies in subtle and not so subtle ways as to how they implement these
standards, and each browser also has its own non-standard additions.
It is a separate art in itself to master the differences between the
browsers. As noted by other posters, the www.quirksmode.org site is a
good starting point.
3) How do you debug javascript? If you make an error, wrong HTML might
show up (this could give you a clue) but also nothing might show up at
all - what do you do then? Stare at the code?

Each browser has its own debugging tools, and there may be other tools
you can get. In IE, if an error occurs, a dialogue box with the line
number appears. In Mozilla, you must open up a specially error window
to check for errors. Otherwise, yes, it is a matter of getting a line
number for the error and staring at the code: but with Javascript it is
not so hard. Most errors are usually to do with typos or wrong data
types (Javascript being loosely typed, subtle errors can creep in).
4) Libraries / collection of often used functions (handling of strings
and dates, numeric stuff, etc.)

The Javascript language spec includes a good selection of the basics
natively.

Outside that, there are again a multitude of libraries/code examples to
be found, varying in quality.
5) A side note: Is it possible in javascript to create variable names
at runtime and access them? Something like (e.g. iterating over input
fields)
for (i=0; i< 10; ++i) {
currField = <construct name of input field i here, e.g. inp0>
currField.value = ...
}

Yes. Research the [ ] notation, which enables strings to be used.

E.g. a call to a method

MyObject["MyMethodName"]();
Any answers to the above questions or further helpful information will
be greatly apprieciated.

Read this newsgroup regularly? It certainly helps me.
 
H

Helmut Giese

Thanks to all of you who responded. I apologize for not answering
sooner but Oct. 14th is our wedding day, so yesterday evening was not
a suitable time to sit in front of my box :)
Yes, I will certainly get one of the books you recommended - I'll go
over to Amazon right away. Also, the links you provided give me lots
of stuff to look at over the weekend, so I guess I will start making
progress.
This news group seems to be a very friendly one, rest assured that
I'll be back sooner or later - rather sooner, given the circumstances
:(
Thanks for the comforting 'welcome' you provided to a newcomer and a
nice weekend to all of you.
Best regards
Helmut Giese
 
P

peterS.

hi Helmut,
...
I am a rather experienced C programmer. However, today I got a
javascript assignment because someone left ... and I never have
done any web stuff before ...

if you are forced to dig yourself deeper into
the javascript core read almost everything of
Douglas Crockfords statements unto javascript
and some of the linked third party sources at:

http://www.crockford.com/javascript/

but don't miss:

http://www.crockford.com/javascript/survey.html
http://www.crockford.com/javascript/private.html
http://www.crockford.com/javascript/inheritance.html
http://www.crockford.com/javascript/remedial.html

and since you are a C programmer and therfore not
unfamiliar to Lint verify your code with JSLint:

http://www.crockford.com/jslint/index.html


bye - peterS.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,263
Messages
2,571,064
Members
48,769
Latest member
Clifft

Latest Threads

Top