How do I select the textfield element "member-name"?
function revealPaywall (){
const paywall = document.getElementById('paywall')
const name = localStorage.getItem("value");
//TO WRITE MULTILINE HTML IN JS, USE BACKTICKS `` TO CREATE A TEMPLATE LITERAL
if (localStorage.getItem("value") === null){
paywall.innerHTML =
`
<h1>This Is An Example Of A Paywall<h1>
<p>If you enter a name, it will be saved to the localStorage. To bypass just enter your name and click the "submit" button<p>
<label for="name">Member Name:</label>
<input type="text" id="member-name">
<br><br><br>
<button onclick="paywallComplete()">SUBMIT</button>
`
}
}
function paywallComplete (){
const paywallName = document.querySelector("#member-name");
if (paywallName.value === null){
window.alert('hi');
}
Am I selecting it correctly? if so why am I not getting a 'hi' alert when clicking on the submit button. I press it with the textfield empty so I'm assuming the paywallName.value === null should be true. I tried querySelector(#member-name) & querySelector(member-name) to no avail.
paywallName.value === null should be trueNo. Empty string is not exactly equal to null.paywallName.valueto see what it actually is to debug yourifstatement:console.log(typeof paywallName.value, paywallName.value).