Question:
Why do websites use javascript?
C.Mellz
2010-05-31 11:40:57 UTC
I want to know like whats the purpose of javascript. I asked a question very similar to this a few days ago and didnt find the answer i was looking for. Can anyone tell me for example why do youtube use javascript?....And are there any javascript coders that can help me with more code? plzzzz....i think im gonna give up on learning this javascript thing it's really getting on my nerves.....
Six answers:
Germann A
2010-05-31 11:45:25 UTC
It is used to make pages dynamic (change appearance), you may create one page to show your photos and change photo address (URL) with JavaScript to show further photos on the same page...
?
2010-05-31 13:17:22 UTC
Javascript is used to execute logic in your webpage.



For instance, let's say you have a text box on your webpage in which the user is supposed to key a number before they submit the form. But some goofball keys the word "hippie" instead, and then hits the "submit" button.



Well, your server side code (PHP, or ASP, or JSP, or OWA, or Cold Fusion or whatever ... ) probably catches the error and sends the webpage back to the use with a message like, "Please Enter Numeric Data Here".



Well, that's okay, but you've wasted alot of time sending the web page back to the server, and then sending right back to the user. Plus, if there are other fields the user might have filled in, you have to make sure to put those values back when the webpage is sent back to the user.



Javascript, on the other hand, can do things like check text boxes to see if they have numeric data, and can prevent the form from submitting AT ALL, and can pop an alert box on the screen to tell the user what the problem is. This is much faster than waiting for the server side code.



Javascript code can be run when fields or buttons are clicked, or even on "mouseover" events. It can make objects (like buttons or pop-lists) visible or invisible depending on what else goes on in a form.



Like a regular programming language, it has loops, conditionals, mathematical operators, the ability to run other blocks of JavaScript code (they're called "functions" whether they return a value or not), and pretty much everything else a programming language can do.



Javascript is really very useful for making your web pages react to what a user is doing. I've never written a webpage that doesn't make EXTENSIVE use of Javascript.
Stephan W
2010-05-31 11:57:27 UTC
Basic HTML pages are not very interactive. All they support is links to other pages (or the page itself) with parameters that can be evaluated on the web server. But all the work is done at the web server!



Javascript is a way to do some of the work inside the browser and make the page react directly on user actions without the need to reload the whole page.



Just one example: Think of a text input field like the one I am typing this into right now. Maybe you want to limit the number of characters a comment can have. Wouldn't it then be nice to let the user know how many characters he has left? Without Javascript you would have to send the input to the server, have the scripts there count the characters, and reply with a page containing the updated counter. And you would have to do this for _every_ single character the user enters.

With Javascript you can have a script embedded into the page, that updates the counter without having to wait for the server.
2010-05-31 11:47:03 UTC
It's mainly to add interactivity to a site. Without javascript sites would be very static and things like mouse hover drop down lists and light up buttons won't exist. Youtube uses javascript to display the voting buttons when you hover above a comment and make things highlight when you hover above them. In all though I would say it's note really worth learning unless you want to be a website designer.
2010-05-31 11:50:54 UTC
The only things that run in the browser are HTML, CSS and Javascript. The only one that does anything is Javascript. HTML is just content. just puts a picture at that spot, it doesn't do anything if you put the cursor on the picture or click the picture - you need Javascript for that. (CSS is just look - make this that color, put this over there.)
hren
2016-10-18 13:29:19 UTC
i do no longer think of which you have sufficient time. JS is perplexing to take up in a pair days. w3schools is particularly the finest. you are able to attempt something like the recent Boston yet you're finding at Hours of video clips.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...