JavaScript Tutorials
- What is Javascript?
- What is BOM?
- What is DOM?
- Variable
- check variable value is empty
- JavaScript Output
- Functions
- Javascript Events
- Input Events
- onchange Event
- Javascript Output methods
- If else statement
- Arrays
- Pattern Validation
- Form Validation
- Inner Html Form Validation
- Inline Form Validation
- Checkbox Validation
- Inline Inner Html Form Validation
- Server side php Validation
- Validate a HTML Form with PHP
- window and window location
- Get Text Value
- Get hidden field value
- JavaScript & PHP
- Date Format
- get php value in javascript
- Redirect page & Autoredirect page
- Auto Refresh page & Div
- How to get select text value from Dropdown box
- How to clear browser history in javascript
- Checkbox Problems
- Select option problems
- Popup Contact Form
- Sidebar Contact Form
- How to use a multistep Form or Form wizard
- Auto Calculate Price
- print Application Form
- Auto Calculate GST in Javascript by select price
- Calculate GST by input value in text box Jquery
- Calculate Discount
- onClick Checkbox
- autofil form data click on checkbox
- Show subcategory list
- Show city list as per state
- Show district list as per country and state
- Show good morning good night wish
- image upload with preview image
- Print Div Content
- Show modal popup on page load
- filter table data usign javascript.
- Character Limit Validation.
- Validate File 5MB Upload
- Validate Special character
- More File Upload
- Call JavaScript Function After Page Load
- Drop Down First option Value Disabled --- Please Select ---
- How to Disable Submit Button After Form Submission
- How to disable browser back button using Jquery?
- How to Remove selected item from second & third dropdown list?
- Interview Questions of JavaScript.
Important Link
Home » JavaScript »
Display outputs
JavaScript Display Possibilities :-
JavaScript can "display" data in different ways:
- Writing into an alert box using window.alert().
- Writing into the HTML output using document.write().
- Writing into an HTML element using innerHTML.
- Writing into the browser console using console.log().
Using window.alert()
You can use an alert box to display data:
Examples window alert :-
File Name:- index.php
<!DOCTYPE html><html>
<body>
<h1>My First Web Page</h1>
<p>My first paragraph.</p>
<script>window.alert(5 + 6);
</script></body>
</html>
Using document.write()
For testing purposes, it is convenient to use document.write():
Examples document.write :-
File Name:- index.php
<!DOCTYPE html><html>
<body>
<h1>My First Web Page</h1>
<p>My first paragraph.</p>
<script>document.write(5 + 6);
</script>
</body>
</html>
Using innerHTML
To access an HTML element, JavaScript can use the document.getElementById(id) method. The id attribute defines the HTML element. The innerHTML property defines the HTML content:
Examples innerHtml :-
File Name:- index.php
<!DOCTYPE html><html>
<body>
<h1>My First Web Page</h1>
<p>My First Paragraph</p>
<p id="demo"></p><script>document.getElementById("demo").innerHTML = 5 + 6;
</script>
</body>
</html>
Using console.log()
In your browser, you can use the console.log() method to display data. Activate the browser console with F12, and select "Console" in the menu.
Examples console.log() :-
File Name:- index.php
<!DOCTYPE html><html>
<body>
<h1>My First Web Page</h1>
<p>My first paragraph.</p>
<script>console.log(5 + 6);</script>
</body>
</html>