Programming Scripts Articles - Page 32 of 37

How to match a regular expression against a string?

Nancy Den
Updated on 23-Jun-2020 08:51:16

362 Views

Use the match() method to match a regular expression against a string in JavaScript. You can try to run the following code to match a regular expression −The following is the parameter −match( param ) − A regular expression object.ExampleYou can try to run the following code to match a regular expression against a string −           JavaScript String match() Method                        var str = "For more information, see Chapter 3.4.5.1";          var re = /(chapter \d+(\.\d)*)/i;          var found = str.match( re );                    document.write(found );          

How to search the value of the href attribute of a link in JavaScript?

Vikyath Ram
Updated on 18-Nov-2023 03:22:23

2K+ Views

To get the value of the href attribute of a link in JavaScript, use the href property. It gives you the URL of the linked document in JavaScript.ExampleYou can try to run the following code to get the value of the href attribute of a link.           Qries                var myLink = document.getElementById("anchorid").href;          document.write("Link: "+myLink);          

How to display the selected option in a dropdown list with JavaScript?

Shubham Vora
Updated on 12-Sep-2023 03:02:04

33K+ Views

In this tutorial, we will learn how to display the selected option in a dropdown list with JavaScript. What is a dropdown list? A dropdown list is a switchable menu that enables users to select one item from various options. A drop-down list is generated with the tag is most frequently used in forms to gather user input. After submitting the form, the name attribute must refer to the form's data. The DOM API functions getElementById() and querySelector() can be used to choose a element. The process use the querySelector() function to first select the "button" and "select" ... Read More

How to show all the options from a dropdown list with JavaScript?

Sharon Christine
Updated on 20-May-2020 08:56:35

5K+ Views

To show all the options from a dropdown list, use the options property. The property allows you to get all the options with length property.ExampleYou can try to run the following code to get all the options from a drop-down list.Live Demo                                 One             Two             Three                                 Click the button to get all the options                function display() {             var a, i, options;             a = document.getElementById("selectNow");             options = "";             for (i = 0; i < a.length; i++) {                options = options + " " + a.options[i].text;             }             document.write("DropDown Options: "+options);          }          

How to convert String to Boolean in JavaScript?

Fendadis John
Updated on 20-May-2020 08:55:35

308 Views

You can try to run the following to learn how to convert String to Boolean in JavaScript.ExampleLive Demo           Convert String to Boolean                var myString = "Amit";          document.write("Boolean : " + Boolean(myString));          

How to return a number indicating the Unicode value of the character?

Alankritha Ammu
Updated on 23-Jun-2020 08:41:29

406 Views

The charCodeAt() method returns a number indicating the Unicode value of the character at the given index. Unicode code points range from 0 to 1, 114, 111. The first 128 Unicode code points are a direct match of the ASCII character encoding.The following parameter is supported by charCodeAt(index) −index − An integer between 0 and 1 less than the length of the string; if unspecified, defaults to 0.ExampleYou can try to run the following code to return a number indicating the Unicode value of the character −           JavaScript String charCodeAt() Method           ... Read More

What records are present in JavaScript cookies?

Daniol Thomas
Updated on 23-Jun-2020 08:46:46

238 Views

Your server sends some data to the visitor's browser in the form of a cookie. The browser may accept the cookie. If it does, it is stored as a plain text record on the visitor's hard drive. Now, when the visitor arrives at another page on your site, the browser sends the same cookie to the server for retrieval. Once retrieved, your server knows/remembers what was stored earlier.Cookies are a plain text data record of 5 variable-length fields −Expires − The date the cookie will expire. If this is blank, the cookie will expire when the visitor quits the browser.Domain − The ... Read More

How to return a string value version of the current number?

Manikanth Mani
Updated on 23-Jun-2020 08:42:43

259 Views

The toLocaleString() method returns a string value version of the current number in a format that may vary according to a browser's local settings.ExampleYou can try to run the following code to return a string value version −           JavaScript toLocaleString() Method                        var num = new Number(150.1234);          document.write( num.toLocaleString());          

How to force a number to display in exponential notation?

Sravani S
Updated on 23-Jun-2020 08:43:16

1K+ Views

Use the toExponential() method to force a number to display in exponential notation, even if the number is in the range in which JavaScript normally uses standard notation.The following is the parameter −fractionDigits - An integer specifying the number of digits after the decimal point. Defaults to as many digits as necessary to specify the number.ExampleYou can try to run the following code to force a number to display in exponential function −           Javascript Method toExponential()                        var num=77.1234;          var ... Read More

How to display the title of a document with JavaScript?

Shubham Vora
Updated on 31-Oct-2022 07:15:52

4K+ Views

In this tutorial, we will understand two approaches to display the document's title using JavaScript. Using document.title Property One of the most used methods in JavaScript to access an HTML document’s title is using a document.title property. In the following example, you will learn to get access to the title. After accessing the title in JavaScript, you can manipulate it and change the way it is displayed on a website. Syntax Here you can see how with the use onClick method, we can set the innerHTML of a paragraph within the document. The document.title is used to grab the title, ... Read More

Advertisements