- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 6685 Articles for Javascript
4K+ Views
In this tutorial, we will learn to display the image in the alert or confirm box in JavaScript. The alert() is the JavaScript method that displays the alert or confirms box on the top center of the screen when you invoke it.As a programmer and user, you have seen on many websites that they ask you for confirmation in the dialog box before you delete any precious thing in your user's account. Also, the alert box can be helpful to show some information when a user comes into the web page or a message.So, the default alert box can have only ... Read More
2K+ Views
To show an image in alert box, try to run the following code. Here, an alert image is added to the custom alert box −ExampleLive Demo function functionAlert(msg, myYes) { var confirmBox = $("#confirm"); confirmBox.find(".message").text(msg); confirmBox.find(".yes").unbind().click(function() { confirmBox.hide(); }); confirmBox.find(".yes").click(myYes); ... Read More
458 Views
The best way to initialize a number in JavaScript is to initialize variables while declaring them. Through this, you can easily avoid undefined values.ExampleYou can try to run the following code to initialize a number −Live Demo var deptNum = 20, id = 005; document.write("Department number: "+deptNum);
962 Views
To design a custom JavaScript alert box, try to run the following code. The code uses a JavaScript library jQuery and CSS to create a fancy alert box different from the standard JavaScript alert box −ExampleLive Demo function functionAlert(msg, myYes) { var confirmBox = $("#confirm"); confirmBox.find(".message").text(msg); confirmBox.find(".yes").unbind().click(function() { confirmBox.hide(); }); ... Read More
11K+ Views
In this tutorial, we will learn to change the button label in the confirm box using JavaScript. The confirm box is useful for taking the confirmation from the user. For example, when you try to delete something from your account on some websites, they show you a popup box containing a message like “Are you sure to delete ….?”. Also, it contains the yes and no buttons, which is one kind of confirmation the application takes from the users. JavaScript users can create the confirm box using the .confirm() method, which contains the confirmation message string, ok, and cancel button. ... Read More
43K+ Views
In this tutorial, we will learn to remove the decimal part of the number in JavaScript. While working with JavaScript, many times, developers need to play with the numbers stored in the database and needs to convert float and double numbers into the pure decimal or integer number.In this situation, developers can have multiple methods to truncate the decimal part of the number. We will see different approaches to overcome the above problem.Using the Math.trunc() methodUsing the Bitwise operatorsUsing the Math.ceil() and Math.floor() methodUsing the Math.Trunc() methodThe Math.trunc() is the most popular method to remove the decimal part of JavaScript. ... Read More
139 Views
The best way to convert a number to a string is using the toString() method, with different bases. The method has an optional parameter “radix”, which is used as a base (2, 8, 16) for a numeric value.ExampleYou can try to run the following code to convert a number to a string −Live Demo var num = 10; var val1 = num.toString(); var val2 = num.toString(2); var val3 = num.toString(8); var val4 = num.toString(16); document.write(val1 + "" + val2 + "" + val3 + "" + val4); Output10 1010 12 a
56K+ Views
In this tutorial, we will learn how to pad a number with leading zeros in JavaScript. Padding a number can be done in different ways in JavaScript. In this tutorial, we will see the two most popular ways of doing it − Using the String padStart() method Using the Array object constructor and join() method Using the String padStart() Method In JavaScript, the String object’s padStart() method is useful to pad a number with leading zeros. It takes two parameters, the first one is the total length of the targeted or desired string, and the other one is ... Read More
3K+ Views
With JavaScript, use the % operator to get the decimal portion of a number.ExampleYou can try to run the following to get decimal portion −Live Demo var num1 = 5.3; var num2 = 4.2; var num3 = 8.6; document.write(num1 % 1); document.write(""+num2 % 1); document.write(""+num3 % 1); Output0.2999999999999998 0.20000000000000018 0.5999999999999996
48K+ Views
In this tutorial, we will learn to check whether a checkbox is checked in JavaScript. The checkbox is the input type in the HTML, which works as the selection box. The radio buttons which belong to the same group allow users to select only one value. Still, the checkbox which belongs to the same group allows users to select multiple values. Also, you have many uses of checkboxes in your mind yourself. The HTML can add a checkbox to the webpage, but to add the behaviour to the checkbox, we must use JavaScript. Programmers can add different behaviours to the ... Read More