Skip to main content

Posts

Showing posts with the label html

Simple Validation in JavaScript:

Javascript can have simple validations and such an example is given below. Download and use the code. <html> <head> </head> <body> Input numbers between 0 and 5 Submit </body> </html> functions.js function validate() { var x, text; x = document.getElementById("numb").value; if(isNaN(x) || x < 1 || x > 5) { text = "Input not valid"; }else { text = "Input OK"; } document.getElementById("show").innerHTML = text; }

Dialog Boxes in JavaScript

Alert Dialog Box: An alert dialog box is mostly used to give a warning message to the users.Mostly they gives only an "Ok button". Confirmation Dialog Box: A confirmation dialog box is mostly used to take user's consent on any option. It displays a dialog box with two buttons mostly "ok" and "cancel" Prompt Dialog Box: The prompt dialog box is very useful when you want to pop-up a text box to get user input. Thus, it enables you to interact with the user. The user needs to fill in the field and then click OK. If the user clicks the Cancel button, the window method prompt() returns null. <html> <head> </head> <body> Show an Alert Dialog Box Show alert Show a Confirmation Dialog Box Show alert Prompt Dialog Box </body> </html> functions.js: function showalert1(){ alert("Iam an alert") } function showalert2(){ confirm("Iam an alert") } function getValue() ...

Calling a script from an external file

We Can just recall the previous example of image switching to understand how to call script externally.  Let's have a look. <html> <head> </head> <body> click on the image </body> </html> Using the tag <script type="text/javascript" src="functions.js"> </script> we can call the script externally. Always write script in file with extension ".js". functions.js: function imageswitch(){ var image = document.getElementById('switchimage'); if(image.src.match("one")) { image.src = "flower_two.jpg"; } else { image.src = "flower_one.jpg"; } } Note: Make sure that the both html and js file locations are the same or else defime them specifically

Image switching Using JavaScript

Here is the simple code by which images are switched. Download and use the code. click on the image

JavaScript Can Change HTML Content

By using the method "getElementById()" we can change the HTML content as we like. Let's have alook... What Can JavaScript Do? JavaScript can change HTML content. Click Me! As we see on the button click the HTML text changes.

Javascript Intoduction

JavaScript is the programming language of HTML and the Web.JavaScript is the most popular programming language in the world. JavaScript is easy to learn. Javascript can change HTML attributes. We are starting a new journey on Javascript learning. Follow the coming post to learn Javascript. Good Luck !!!

What is CSS Class ?

In CSS, classes allow you to apply a style to a given class of an element. To do this, you link the element to the style by declaring a style for the class, then assigning that class to the element. CSS Class Syntax You declare a CSS class by using a dot (.) followed by the class name. You make up the class name yourself. After the class name you simply enter the properties/values that you want to assign to your class. .class-name { property:value; } If you want to use the same class name for multiple elements, but each with a different style, you can prefix the dot with the HTML element name. html-element-name.class-name { property:value; } You can also select elements (or classes) that's nested within another element or class. For example, div.css-section p will select all elements that are nested within a <div> element that uses the .css-section class. One major benefit of doing this is that you don't need to apply a class to every instance of an ele...

Different element with different background in CSS

The example explains how we can color different element with different backgrounds. <head> <style> h1 { background-color: #6395ed; } p { background-color: #e000ff; } div { background-color: #b000de; } </style> </head> <body> I'am colored <div> This is a colored div. This is a colored para We are still in the div element. </div> </body> </html>

Three formats of calling css

Call using tag: We can call a css using the tag like below. td { padding: 5px; text-align: left; background-color: #F2F2F2; } Here all the attribute with td tag will be formatted with this css. Call using id: We can call a css using the id like below and the css will be applied to the particular attribute with this particular id. #p1 { background-color: #00FF00; padding: 2px; } Here all the attribute with td id 'p1' will be formatted with this css and while using id we should call id starting with a hash (#). And in html file <div> This call calls using id </div> Call using class: We can call a css using the attribute 'class' like below and the css will be applied to the particular attribute with this particular class attribute. .p1 { background-color: #00FF00; padding: 2px; } Here all the attribute with td id 'p1' will be formatted with this css and while using id we should ...

CSS - Borders

The border properties allow you to specify how the border of the box representing an element should look. There are three properties of a border you can change The border-color Specifies the color of a border. The border-style Specifies whether a border should be solid, dashed line, double line, or one of the other possible values. The border-width Specifies the width of a border. Now we will see how to use these properties with examples. The border-color Property: The border-color property allows you to change the color of the border surrounding an element. You can individually change the color of the bottom, left, top and right sides of an element's border using the properties: border-bottom-color changes the color of bottom border. border-top-color changes the color of top border. border-left-color changes the color of left border. border-right-color changes the color of right border. The border-style Property: The border-style property allows...

Centering Text with CSS

Centering text and other elements can easily be done with the CSS text-align property. Applying this to an internal or external stylesheet: p {text-align: center;} or this to inline styling: This is centered text

Html Interview Questions

Which browsers support HTML 5? Almost all browsers i.e. Safari, Chrome, Firefox, Opera, Internet Explorer support HTML 5. What is SVG? SVG stands for scalable vector graphics. It’s a text based graphic language which draws images using text, lines, dots etc. This makes it lightweight and renders faster. What is canvas in HTML 5? Canvas is an HTML area on which you can draw graphics. What are the restrictions of Web Worker thread? Web worker threads cannot modify HTML elements, global variables and some window properties like Window.Location. You are free to use javascript data types, XMLHttpRequest calls etc. How to terminate a web worker? w.terminate();

Alert, Confirm, and Prompt boxes in Javascript

The three "commands" involved in creating alert, confirm, and prompt boxes are: window.alert() window.confirm() window.prompt() window.alert() : This command pops up a message box displaying whatever you put in it. <body> <script type="text/javascript"> window.alert("Iam an alert box!!!") </script> </body> window.confirm(): Confirm is used to confirm a user about certain action, and decide between two choices depending on what the user chooses. <body> <script type="text/javascript"> var x=window.confirm("Are you sure?") if (x) window.alert("Yes!") else window.alert("No") </script> </body> window.prompt(): Prompt is used to allow a user to enter something, and do something with that info: <body> <script type="text/javascript"> var y=window.prompt("Enter your name here...") window.alert(y) </script> </body> ...

Formatting and Styling Text in CSS

Text indention [text-indent] The property text-indent allows you to add an elegant touch to text paragraphs by applying an indent to the first line of the paragraph. p { text-indent: 10px; } Text alignment [text-align] The CSS property text-align corresponds to the attribute align used in old versions of HTML. Text can either be aligned to the left, to the right or centred. In addition to this, the value justify will stretch each line so that both the right and left margins are straight. p { text-align: left; } h1{ text-align: right; } h2{ text-align: center; } b { text-align: justify; } Text decoration [text-decoration] The property text-decoration makes it is possible to add different "decorations" or "effects" to text. Some properties are underline, overline, line-through. h1 { text-decoration: underline; } h2 { text-decoration: overline; } h3 { text-decoration: l...

Transferring user to new web page automatically

<META HTTP-EQUIV="Refresh" CONTENT="2;URL=http://eazyprogramming.blogspot.in/"> Use the code above inside your head tag and your web page will be redirected to "http://eazyprogramming.blogspot.in/" within 2 seconds. Change the value of CONTENT="2" to some other integer to decrease or increase the delay of redirection of webpage.If "0" is given the change will be seen immediately.

Properties with Colors and Backgrounds in CSS

Foreground color: the 'color' property The color property describes the foreground color of an element. Sample code is given below copy and try it out... h1 { color: #990099; } h3{ color: #999999; } p { color: #990099; } 'background-color' property The background-color property describes the background color of elements. Sample code is given below copy and try it out... h1 { background-color: #990099; } h3{ background-color: #999999; } p { background-color: #990099; } Background images [background-image] The CSS property background-image is used to insert a background image. Sample code is given below copy and try it out... body { background-color: #FFCC66; background-image: url("016.jpg"); } Repeat background image [background-repeat] This property describes whether background image has to repeat or not,because if given by default it will repeat horizontally. background-repeat: repeat - image will be repea...

Calling an External CSS to HTML document

An external style sheet is simply a text file with the extension .css. Suppose our CSS file is inside the folder named "style" and the CSS file with file name "newstyles.css".The the code to link the html with CSS is given below .. <link rel="stylesheet" type="text/css" href="style/newstyles.css" /> The line of code must be inserted in the header section of the HTML code. And if you have to give different style to different attribute you can see the sample code below.. Get the sample source code for "test.html" which is connected to an external CSS named "newstyles.css". <html> <head> My sample document </head> <body> My first stylish header My second stylish header My paragraph </body> </html> Get the sample source code for "newstyles.css". body { background-color: #00FF00; } h1 { color: #990099; backgro...

Applying CSS to an HTML document - 3 Methods

There are three ways you can apply CSS to an HTML document. In-line (the attribute style) One way to apply CSS to HTML is by using the HTML attribute style . <html> <head> Sample </head> <body style="background-color: #00FF00;"> The background color is green </body> </html> Internal (the tag style) Another way is to include the CSS codes using the HTML tag <style>. <html> <head> <title>Example</title> <style type="text/css"> body {background-color: #00FF00;} </style> </head> <body> <p>The background color is green </p> </body> </html> External (link to a style sheet) The last method is to link to an external CSS file.An external style sheet is simply a text file with the extension .css. Suppose our CSS file is inside the folder named "style" and the CSS file with file name ...