Set - 2

Question 1 :

How to add Buttons in JavaScript?

Answer :

The most basic and ancient use of buttons are the "submit" and "clear", which appear slightly before the Pleistocene period. Notice when the "GO!" button is pressed it submits itself to itself and appends the name in the URL.

<form action="" name="buttonsGalore" method="get">
	Your Name: <input type="text" name="mytext" /><br />
	<input type="submit" value="GO!" />
	<input type="reset" value="Clear All" />

Another useful approach is to set the "type" to "button" and use the "onclick" event.

<script type="text/javascript">
	function displayHero(button) {
		alert("Your hero is \""+button.value+"\".");

<form action="" name="buttonsGalore" method="get">
	<fieldset style="margin: 1em; text-align: center;">
        <legend>Select a Hero</legend>
        <input type="button" value="Agamemnon" onClick="displayHero(this)" />
        <input type="button" value="Achilles" onClick="displayHero(this)" />
        <input type="button" value="Hector" onClick="displayHero(this)" />
		<div style="height: 1em;" />


Question 2 :

What can javascript programs do?

Answer :

Generation of HTML pages on-the-fly without accessing the Web server. The user can be given control over the browser like User input validation Simple computations can be performed on the client's machine The user's browser, OS, screen size, etc. can be detected Date and Time Handling

Question 3 :

How to set a HTML document's background color?

Answer :

document.bgcolor property can be set to any appropriate color.

Question 4 :

How can JavaScript be used to personalize or tailor a Web site to fit individual users?

Answer :

JavaScript allows a Web page to perform "if-then" kinds of decisions based on browser version, operating system, user input, and, in more recent browsers, details about the screen size in which the browser is running. While a server CGI program can make some of those same kinds of decisions, not everyone has access to or the expertise to create CGI programs. For example, an experienced CGI programmer can examine information about the browser whenever a request for a page is made; thus a server so equipped might serve up one page for Navigator users and a different page for Internet Explorer users. Beyond browser and operating system version, a CGI program can't know more about the environment. But a JavaScript-enhanced page can instruct the browser to render only certain content based on the browser, operating system, and even the screen size.
Scripting can even go further if the page author desires. For example, the author may include a preference screen that lets the user determine the desired background and text color combination. A script can save this information on the client in a well-regulated local file called a cookie. The next time the user comes to the site, scripts in its pages look to the cookie info and render the page in the color combination selected previously. The server is none the wiser, nor does it have to store any visitor-specific information.

Question 5 :

Are you concerned that older browsers don't support JavaScript and thus exclude a set of Web users? individual users?

Answer :

Fragmentation of the installed base of browsers will only get worse. By definition, it can never improve unless absolutely everyone on the planet threw away their old browsers and upgraded to the latest gee-whiz versions. But even then, there are plenty of discrepancies between the scriptability of the latest Netscape Navigator and Microsoft Internet Explorer.
The situation makes scripting a challenge, especially for newcomers who may not be aware of the limitations of earlier browsers. A lot of effort in my books and ancillary material goes toward helping scripters know what features work in which browsers and how to either workaround limitations in earlier browsers or raise the compatibility common denominator.
Designing scripts for a Web site requires making some hard decisions about if, when, and how to implement the advantages scripting offers a page to your audience. For public Web sites, I recommend using scripting in an additive way: let sufficient content stand on its own, but let scriptable browser users receive an enhanced experience, preferably with the same HTML document.