Javascript Articles

Page 450 of 534

What is oncontextmenu event in JavaScript?

usharani
usharani
Updated on 19-Jun-2020 513 Views

On right click of an element, when the context menu opens, then it is known as oncontextmenu in JavaScript.ExampleYou can try to run the following code to learn how to work with oncontextmenu event in JavaScript −                                         Right click    

Read More

How can we debug JavaScript in Internet Explorer?

Srinivas Gorla
Srinivas Gorla
Updated on 19-Jun-2020 255 Views

The most basic way to track down errors is by turning on error information in your browser. By default, Internet Explorer shows an error icon in the status bar when an error occurs on the page. Double-clicking this icon takes you to a dialog box showing information about the specific error that occurred. Since this icon is easy to overlook, Internet Explorer gives you the option to automatically show the Error dialog box whenever an error occurs. To enable this option, select Tools → Internet Options → Advanced tab. and then finally check the "Display a Notification About Every Script Error" box option as ...

Read More

How to do basic form validation using JavaScript?

Vrundesha Joshi
Vrundesha Joshi
Updated on 19-Jun-2020 798 Views

JavaScript provides a way to validate form's data on the client's computer before sending it to the web server. Basic form validation includes the form to be checked to make sure all the mandatory fields are filled in. It would require just a loop through each field in the form and check for data.ExampleYou can try to run the following code to implement basic form validation in JavaScript −           Form Validation                // Form validation          function validate(){             if( document.myForm.Name.value ...

Read More

What is onerror() Method in JavaScript?

Abhinaya
Abhinaya
Updated on 19-Jun-2020 2K+ Views

The onerror event handler was the first feature to facilitate error handling in JavaScript. The error event is fired on the window object whenever an exception occurs on the page.ExampleYou can try to run the following code to implement onerror() method in JavaScript −                                         Click the following to see the result:                          

Read More

How to convert PHP array to JavaScript array?

Jennifer Nicholas
Jennifer Nicholas
Updated on 18-Jun-2020 3K+ Views

You can use PHP array in JavaScript. It works for the single as well as the multidimensional array. Use the json_encode() method to achieve this.Let’s say Our PHP array is −$myArr = array('Amit', 'amit@example.com');Converting PHP array into JavaScript. var arr = ; Now, let’s finally learn how to access it to output the email −document.write(arr[1]);

Read More

How to get time difference between two timestamps in seconds?

Arushi
Arushi
Updated on 18-Jun-2020 3K+ Views

To get the time difference between two timestamps, try to run the following code. Here, we are calculating the total number of hours, minutes and seconds between two timestamps −ExampleLive Demo           JavaScript Dates                          var date1, date2;            date1 = new Date( "Jan 1, 2018 11:10:05" );          document.write(""+date1);          date2 = new Date( "Jan 1, 2018 08:15:10" );          document.write(""+date2);          var res ...

Read More

How to convert a Unix timestamp to time in JavaScript?

Smita Kapse
Smita Kapse
Updated on 18-Jun-2020 268 Views

To convert a Unix timestamp to time, you can try to run the following code in JavaScript −ExampleLive Demo           JavaScript Dates                        var unix_time = 1514791901 ;          var date = new Date(unix_time*1000);          // get hours          var hrs = date.getHours();          // get minutes          var min = "0" + date.getMinutes();          // get seconds          var sec = "0" + date.getSeconds();          document.write("Time- "+hrs + ":" + min.substr(-2) + ":" + sec.substr(-2));           OutputTime- 13:01:41

Read More

How to get current date/time in seconds in JavaScript?

Abhinanda Shri
Abhinanda Shri
Updated on 18-Jun-2020 731 Views

To convert time in seconds, firstly get the current time. Then, multiply the hours to 3600 and minutes to 60; rest you can see below −(hours*3600) + (min*60) + secExampleYou can try to run the following code to get the current time in seconds −Live Demo           JavaScript Get Seconds                        var dt = new Date();          var sec = dt.getSeconds();          document.write("Seconds: " + sec);          var min = dt.getMinutes();          document.write("Minutes: " + min);          var hrs = dt.getHours();          document.write("Hours: " + hrs);          var total_seconds = (hrs*3600) + (min*60) + sec;          document.write("Total seconds: " + total_seconds) ;           OutputSeconds: 35 Minutes: 37 Hours: 9 Total seconds: 34655

Read More

How to compare two JavaScript Date Objects?

Ramu Prasad
Ramu Prasad
Updated on 18-Jun-2020 401 Views

To compare two date objects with JavaScript, create two dates object and get the recent date to compare it with the custom date.ExampleYou can try to run the following code to compare two dates −Live Demo                    var date1, date2;          date1 = new Date();          document.write(date1);          date2 = new Date( "Dec 10, 2015 20:15:10" );          document.write(""+date2);          if (date1 > date2) {             document.write("Date1 is the recent date.");          } else {             document.write("Date 2 is the recent date.");          }           OutputMon May 28 2018 09:48:49 GMT+0530 (India Standard Time) Thu Dec 10 2015 20:15:10 GMT+0530 (India Standard Time) Date1 is the recent date

Read More

What is the best way to initialize a JavaScript Date to midnight?

V Jyothi
V Jyothi
Updated on 18-Jun-2020 554 Views

To initialize a JavaScript Date to midnight, set hours like the following −setHours(0,0,0,0);ExampleYou can try to run the following code to set a date to midnight −Live Demo                    var dt;          dt = new Date();          dt.setHours(0,0,0,0);          document.write(dt);           OutputMon May 28 2018 00:00:00 GMT+0530 (India Standard Time)

Read More
Showing 4491–4500 of 5,338 articles
« Prev 1 448 449 450 451 452 534 Next »
Advertisements