The Crossover Between JS and PHP

Ok, so if you want to -completely- get what I’m trying to get at maybe you should have a quick scan over the thread The Dynamic Nature of JavaScript.

And now lets just have a quick re-read over what Jeremy Keith says in his DOM Scripting book on page 80 - Question everything:

Whenever you use JavaScript to alter the behavior of your web pages, you should question your decision. First and foremost, you should question whether the extra behavior is really necessary.

JavaScript has been misused in the past to add all sorts of pointless bells and whistles to websites.

– Blah blah blah, two paragraphs on pop-up / pop-under windows which I never use so irrelevant to use in the quote –

If only someone had asked, “How will this benefit the user?”

Ok let’s get down to business :wink:

So I understand that JavaScript is used to alter the behavior of Web pages to enhance the user interface or add useful Web page interactivity and so on. And my understanding on the dynamic nature of JavaScript is greater than before too.

Paul Wilkins mentions in the thread linked above the following statement:

[QUOTE=pmw57;4513514]When using scripting, the best solution is to leave the page content on the page, where it belongs, and then to use scripting to affect the behaviour of the page, which can include hiding parts of the page content until some event occurs later on.[/QUOTE]

But what about the dynamic parts of JavaScript that can’t be added to the markup of the HTML document (I mean the “View Source” HTML markup) such as a JS date script which could also be implemented with a server-side scripting language such as ASP.NET or PHP? Perhaps someone could enlighten me about why people use scripts to display the on Websites when the date can be seen in the taskbar? And why insert it with JS (like the Website of the UK Government Website Direct.gov.uk does) when it can be inserted with PHP and it would actually be indexed (at least thats what I know it to be)? Or is this the same case as most other Websites whereby it may be a credible company / organisation but the Web Designer / Developer wasn’t so credible?

How do you decide whether to use JavaScript or a server-side scripting language to insert dynamic information on to a Web page? Any particular advantages / disadvantages that should be known and taken into consideration?

Thanks in advance!

Andrew Cooper

as far as the date on that web page-
Seems more like useless eye candy to me in this case. Sometimes you want to show a date/time, for example when asking the user for a date/time, you might want to show them the servers notion of the current time to use as a reference point. But that doesn’t appear to be the case for that page.

For something like this, js is a great choice. Since it’s not easy for the server to properly determine an accurate local time for the visitor, yet it’s very easy for js, it might be preferable to simply not show the time when js is disabled, instead of showing a backup time generated by the server, which has a higher chance of being wrong for that visitor.

Because some people may not have access to, or know how to make use of, server-side coding.

Many web sites are built to a budget. As such there is often not the budget to do things properly; only well enough for the perceived majority of the audience.

My opinion is to use server-side code for as much of the dynamic information as possible, which provides access to that information from non-scripting environments.

I’ve noticed that the more I learn about JavaScript, the less I am inclined to rely on it.

Provide as much of the experience as you possibly can from a non-scripted environment, which helps to improve a large amount of accessibility issues. Then you can take over with JavaScript to improve the user experience, by reducing the number of page-loads, or enhancing what is already there.

I understand what you’re saying. They may not have access to a server with PHP and MySQL available or ASP.NET or Python etc or they may have access but don’t know any server-side coding. However this doesn’t answer my question:

Why people use scripts to display them on Websites when the date can be seen in the taskbar?

I’d just like your opinion on this - If you was the Web Designer / Developer or part of the Web team that created the Direct.gov.uk Website would you include the date on the Website as they have done? Whether yes or no, what would be the reason for your decision?

Also, how would you implement it? Through JavaScript or a server-side language?

Indeed, I agree on this. I’m also the same. Although before I started learning JavaScript I never used it, I hated the existance of JavaScript and said to myself I’d never use JavaScript I’ve come to learn JavaScript and liking JavaScript but only using it when absolutely necessary. Despite spending a lot of money and time on learning it I still don’t think I’ll rely on it an awful lot.

Any particular reason why you think it is useless eye candy? Would you ever include a date like this on a Website? Whether you would or not, please tell me why.

Why do you think they used JS to display the date on the Web page though? They have the same on the MSN Website too.

Thanks for the feedback and advise so far guys! :tup:

Andrew Cooper

One reason is to help assure people that your page isn’t out of date.
Other reasons can relate to web kiosks, which run in a full-screen view.
A third reason is that the date is on the page when it’s printed.

I would implement it with a server-side language. However, doing that doesn’t take in to account user timezones.

If I in New Zealand were to visit the UK page, I would get yesterdays date were I to visit before midday, and if the site is in the US then the time difference can be more like 18 hours behind.

Using javascript allows the local computer date/time to be shown instead, but that can introduce a whole range of different problems relating to the accuracy of the local computer’s time.

Simply because I can’t think of a good reason to have it there. I don’t claim to be someone to listen to on usability subjects. There could be a good reason I’m not aware of. But, I think few people benefit from being told what the date is.

But, if it’s important, or useful to state the current date/time because there’s other dates being displayed on the page(records displayed, or user input required) then I can see showing a date as being a good thing.