Table of contents
- HTML
- Java Script
- When to create a function in JS?
- How to create a function in JS?
- How to get input from html element into JavaScript?
- how to convert string data type to int data type?
- When to use while loop?
- how to return data from JavaScript to HTML element with an ID attribute?
- how to get certain portion of an array using indices?
Today's day 3 Goal is to write code in JavaScript and some minor adjustments in my project backupcal.
HTML
How to get user input from click in html?
- To Get user click (input)and initiate a function every time this button is clicked, write the following code:
<button onclick="functionname()">clickme</button>
Now,
Java Script
When to create a function in JS?
- A Function will help in calling it application, as in my case I need call a function when user clicks.
How to create a function in JS?
- Function in JavaScript syntax.
function functionname()
{
Your Code
}
How to get input from html element into JavaScript?
- Use the following code to get input from HTML element with an Id attribute and assign it to variable x:
Var x = document.getElementById("Id name").value
how to convert string data type to int data type?
- We need to convert the string data input from get element by ID to Numerical int Data Type, type the following code:
parseInt(document.getElementById("Idname").value)
When to use while loop?
- When there is a situation to increment a number while it checks some condition. Use the following while syntax.
while (condition)
{
your code
}
- Use while loop with caution.
how to return data from JavaScript to HTML element with an ID attribute?
- After performing Arithmetic operations, use the following code to return data to html element:
document.getElementById("Idname").innerHTML = x;
how to get certain portion of an array using indices?
- JavaScript returns time as string so in order to access the hour we use slice() method.
var x = "string";
var y=x.slice(0,2);
console.log(y);
Given below is the output to the following code above:
St
Conclusion: In this blog I have discussed the following challenges I face when I am building idea:
Assigning a function whenever a click is registered.
Creating a function
Importing data from HTML element into JavaScript variable.
Converting string to numerical Int data type.
Using while loop with caution.
How to return data from JavaScript to HTML element by ID.
How to use slice() method.
My Own Project Backupcal code:
Author: Dheeraj.y