Skip to content

Latest commit

 

History

History
65 lines (51 loc) · 1.59 KB

clv9hil0z000108ju12ha1mre.md

File metadata and controls

65 lines (51 loc) · 1.59 KB
title datePublished cuid slug
JavaScript User Inputs
Sun Apr 21 2024 12:08:34 GMT+0000 (Coordinated Universal Time)
clv9hil0z000108ju12ha1mre
javascript-user-inputs

Handling user inputs effectively will make your web page stand out.

The confirm () box asks the user to accept or reject something. Similar to alert () and prompt (), the box takes the focus away from the current window and forces the user to read the message.

You can store the decision from the user in a variable and use it later in your code. A confirm () box returns true if the user clicks OK and false if the user clicks on Cancel.

In a similar way, a checkbox represents two states, selected (true) or deselected (false).

You can use .checked to get the state of the checkbox.

<form id="myForm">
  <label for="c1">Tick this box</label>
  <input type="checkbox" id="c1"></br></br>
  <input type="button" onclick="checkTicked()" value="Check if Ticked"></input>
</form>
#table {
  background-color: #525252;
  padding: 20px;
  color: white;
}

#dataTable {
  width: 60%;
  margin: 0 auto;
  border-collapse: collapse;
  color: white;
}

th, td {
  border: 1px solid #DDDDDD;
  padding: 8px;
}

th {
  background-color: #494949;
  padding-top: 12px; 
  padding-bottom: 12px; 
  text-align: left;
}

h2 {
  text-align: center;
}
function checkTicked() {
  let box = document.getElementById("c1");
  console.log(box.checked);
}

A checkbox in a news site is used to "Accept Terms & Conditions". The checkbox element has been accessed and stored in variable called terms.