If function is true then do this

I’m trying to figure out how to make this work.

I want the validation function to check if all the user inputs are true, then a message in success ID will show You have successfully created an account. once the submit button is clicked.

HTML:

<html>
  <head>
    <title>Simple Registration Form</title>
    <link rel="stylesheet" href="style.css" />
    <script type="text/javascript" src="script.js"></script>
  </head>
  <body>
    <form id="myForm" action="#">
      <div class="container">
        <div class="content">
          <label>
            First name:
            <br /><input
              type="text"
              id="fname"
              placeholder="Enter first name"
            /><br />
            <span class="notif" id="fn"></span><br />
          </label>

          <label>
            Last name:
            <br /><input
              type="text"
              id="lname"
              placeholder="Enter last name"
            /><br />
            <span class="notif" id="ln"></span><br />
          </label>

          <label>
            Birthdate:
            <br /><input
              type="date"
              id="birthdate"
              placeholder="Enter birthdate"
            /><br />
            <span class="notif" id="bday"></span>
          </label>

          <label>
            <br />Gender: <br /><select id="gender">
              <option value="select">Select</option>
              <option value="male">Male</option>
              <option value="female">Female</option></select
            ><br />
            <span class="notif" id="gndr"></span><br />
          </label>
        </div>
        <div class="content">
          <label>
            Username:
            <br /><input
              type="text"
              id="username"
              placeholder="Enter username"
              pattern="[a-zA-Z]+"
            /><br />
            <span class="notif" id="usr"></span><br />
            <div id="msg">
              <p id="alphabets" class="invalid">Alphabets only.</p>
            </div>
            <br />
          </label>

          <label>
            E-mail:
            <br /><input
              type="email"
              id="email"
              placeholder="Enter e-mail"
            /><br />
            <span class="notif" id="eml"></span><br />
            <div id="emlForm">
              <p id="emailFormat" class="invalid">Invalid format.</p>
            </div>
            <br />
          </label>

          <label>
            Confirm E-mail:
            <br /><input
              type="email"
              id="econf"
              placeholder="Retype e-mail"
            /><br />
            <span class="notif" id="rt-eml"></span><br />
          </label>

          <label>
            Password:
            <br /><input
              type="password"
              id="password"
              placeholder="Enter password"
            /><br />
            <span class="notif" id="pass"></span><br />
            <div id="message">
              <p id="letter" class="invalid">Lowercase letter</p>
              <p id="capital" class="invalid">Uppercase letter</p>
              <p id="number" class="invalid">Number</p>
              <p id="special" class="invalid">Special character</p>
              <p id="length" class="invalid">Minimum 8 characters</p>
            </div>
            <br />
          </label>

          <label>
            Confirm Password:
            <br /><input
              type="password"
              id="pconf"
              placeholder="Retype password"
            /><br />
            <span class="notif" id="rt-pass"></span><br />
          </label>
        </div>

        <div>
          <input
            type="submit"
            class="btn"
            onclick="validation(); validatePassword();"
            value="Submit"
          />
          <input
            type="reset"
            class="btn"
            id="reset"
            onclick="resetErrors();"
            value="Reset"
          />
          <br /><br />
        </div>
        <br /><span class="notif" id="success"></span><br />
      </div>
    </form>
    <script src="script.js"></script>
  </body>
</html>

JS:

function validation() {
  var fname = document.getElementById('fname').value;
  if (fname == '') {
    document.getElementById('fn').innerHTML = 'Please enter first name.';
  }
  var lname = document.getElementById('lname').value;
  if (lname == '') {
    document.getElementById('ln').innerHTML = 'Please enter last name.';
  }
  var birth = document.getElementById('birthdate').value;
  if (birth == '') {
    document.getElementById('bday').innerHTML = 'Please enter birthdate.';
  }
  var gender = document.getElementById('gender').value;
  if (gender == 'select') {
    document.getElementById('gndr').innerHTML = 'Please choose your gender.';
  }
  var username = document.getElementById('username').value;
  if (username == '') {
    document.getElementById('usr').innerHTML = 'Please enter username.';
  }
  var email = document.getElementById('email').value;
  if (email == '') {
    document.getElementById('eml').innerHTML = 'Please enter email.';
  }
  var econf = document.getElementById('econf').value;
  if (econf == '') {
    document.getElementById('rt-eml').innerHTML = 'Please confirm your email.';
  }
  if (econf != email) {
    document.getElementById('rt-eml').innerHTML = 'Email did not match.';
  }
  var password = document.getElementById('password').value;
  if (password == '') {
    document.getElementById('pass').innerHTML = 'Please enter password.';
  }
  var pconf = document.getElementById('pconf').value;
  if (pconf == '') {
    document.getElementById('rt-pass').innerHTML =
      'Please confirm your password.';
  }
  if (pconf != password) {
    document.getElementById('rt-pass').innerHTML =
      'Password did not match. Try again. ';
  }
}

function reset() {
  document.getElementById('myForm').reset();
}

function resetErrors() {
  document.querySelectorAll('.notif').forEach(el => (el.innerHTML = ''));
}

var alphabetInput = document.getElementById('username');
var alphabets = document.getElementById('alphabets');

alphabetInput.onfocus = function () {
  document.getElementById('msg').style.display = 'block';
};

alphabetInput.onblur = function () {
  document.getElementById('msg').style.display = 'none';
};

alphabetInput.onkeyup = function () {
  var alphabetOnly = /^[A-Za-z]+$/;
  if (alphabetInput.value.match(alphabetOnly)) {
    alphabets.classList.remove('invalid');
    alphabets.classList.add('valid');
  } else {
    alphabets.classList.add('valid');
    alphabets.classList.add('invalid');
  }
};

var emailInput = document.getElementById('email');
var emailFormat = document.getElementById('emailFormat');

emailInput.onfocus = function () {
  document.getElementById('emlForm').style.display = 'block';
};

emailInput.onblur = function () {
  document.getElementById('emlForm').style.display = 'none';
};

emailInput.onkeyup = function () {
  var emlFormat = /[@]/;
  if (emailInput.value.match(emlFormat)) {
    emailFormat.classList.remove('invalid');
    emailFormat.classList.add('valid');
  } else {
    emailFormat.classList.add('valid');
    emailFormat.classList.add('invalid');
  }
};

var myInput = document.getElementById('password');
var letter = document.getElementById('letter');
var capital = document.getElementById('capital');
var number = document.getElementById('number');
var length = document.getElementById('length');
var special = document.getElementById('special');

myInput.onfocus = function () {
  document.getElementById('message').style.display = 'block';
};

myInput.onblur = function () {
  document.getElementById('message').style.display = 'none';
};

myInput.onkeyup = function () {
  var lowerCaseLetters = /[a-z]/g;
  if (myInput.value.match(lowerCaseLetters)) {
    letter.classList.remove('invalid');
    letter.classList.add('valid');
  } else {
    letter.classList.remove('valid');
    letter.classList.add('invalid');
  }

  var specialCharacters = /[!@#$%^&*]/g;
  if (myInput.value.match(specialCharacters)) {
    special.classList.remove('invalid');
    special.classList.add('valid');
  } else {
    special.classList.remove('valid');
    special.classList.add('invalid');
  }

  var upperCaseLetters = /[A-Z]/g;
  if (myInput.value.match(upperCaseLetters)) {
    capital.classList.remove('invalid');
    capital.classList.add('valid');
  } else {
    capital.classList.remove('valid');
    capital.classList.add('invalid');
  }

  var numbers = /[0-9]/g;
  if (myInput.value.match(numbers)) {
    number.classList.remove('invalid');
    number.classList.add('valid');
  } else {
    number.classList.remove('valid');
    number.classList.add('invalid');
  }

  if (myInput.value.length >= 8) {
    length.classList.remove('invalid');
    length.classList.add('valid');
  } else {
    length.classList.remove('valid');
    length.classList.add('invalid');
  }
};

var their_date = new Date(2010, 6, 17);
var today = new Date();
var date2 = new Date(
  today.getFullYear(),
  today.getMonth() + 1,
  today.getDate()
);
var diff = new Date(date2.getTime() - their_date.getTime());
console.log(diff.getUTCFullYear() - 1970); // Gives difference as year

CSS:

@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300&display=swap');
* {
  font-family: 'Poppins', sans-serif;
  font-weight: bold;
  margin: 0;
  padding: 0;
  line-height: 1;
  font-size: 14px;
  top: 20%;
}

.container {
  top: 100px;
  position: relative;
  width: 450px;
  max-width: 100%;
  grid-column-gap: 50px;
  margin: auto;
  display: grid;
  grid-template-columns: auto auto;
  padding: 10px;
  box-shadow: 0 3px 10px rgb(0 0 0 / 0.5);
  border-radius: 5px;
}

.content {
  margin: 0;
  padding: 0;
}

.btn {
  margin: 0;
  position: relative;
  top: 50%;
  -ms-transform: translateY(-50%);
  transform: translateY(-50%);
  width: 70px;
  height: 25px;
  cursor: pointer;
  align-items: center;
  border-radius: 5px;
}

.btn:active {
  background-color: rgb(190, 190, 190);
}

.notif {
  font-size: 11px;
  color: red;
}

input[type='date'] {
  overflow: hidden;
  padding: 0;
  width: 140px;
  -webkit-padding-start: 1px;
  border-radius: 5px;
  padding-left: 0.5em;
  font-size: 12px;
}

input[type='text'],
input[type='email'],
input[type='password'] {
  border-radius: 5px;
  padding-left: 0.5em;
  width: 180px;
  font-size: 12px;
}

span[id='success'] {
  color: rgb(0, 202, 0);
}

#message {
  display: none;
  background: #ffffff;
  color: #000;
  padding: 0;
  margin-top: 0;
  margin-left: 5px;
}

#message p {
  padding: 1px 2px;
  font-size: 12px;
}

/* Add a green text color and a "✔" when the requirements are right */
.valid {
  color: green;
}

.valid:before {
  position: relative;
  left: -3px;
  content: '✔';
}

/* Add a red text color and an "x" when the requirements are wrong */
.invalid {
  color: red;
}

.invalid:before {
  position: relative;
  left: -5px;
  content: '✖';
}

:required {
  background: red;
}

#msg {
  display: none;
  background: #ffffff;
  color: #000;
  padding: 0;
  margin-top: 0;
  margin-left: 5px;
}

#msg p {
  padding: 1px 2px;
  font-size: 12px;
}

/* Add a green text color and a "✔" when the requirements are right */
.valid {
  color: green;
}

.valid:before {
  position: relative;
  left: -3px;
  content: '✔';
}

/* Add a red text color and an "x" when the requirements are wrong */
.invalid {
  color: red;
}

.invalid:before {
  position: relative;
  left: -5px;
  content: '✖';
}

:required {
  background: red;
}

#emlForm {
  display: none;
  background: #ffffff;
  color: #000;
  padding: 0;
  margin-top: 0;
  margin-left: 5px;
}

#emlForm p {
  padding: 1px 2px;
  font-size: 12px;
}

/* Add a green text color and a "✔" when the requirements are right */
.valid {
  color: green;
}

.valid:before {
  position: relative;
  left: -3px;
  content: '✔';
}

/* Add a red text color and an "x" when the requirements are wrong */
.invalid {
  color: red;
}

.invalid:before {
  position: relative;
  left: -5px;
  content: '✖';
}

:required {
  background: red;
}

How can I make this work?

How to get list with of property from array of objects unless it contains another item with certain value?

I have an array of objects, and I need to get list with certain property from that array of objects. But i need that list to contain only those values where object was containing another property with certain element.
This is very confusing so i made an example.
Let’s say i have an array with objects.

  employees = [
           {
            n: 'case 1',
            date: '2021-05-4',
            id: '123',
            user: [{name: 'Vlad', id: '1'}, {name: 'Misha', id: '2'}],
            isPresent : false,
           },
           {
            caseName: 'case 2',
            date: '2021-05-4',
            id: '124',
            user: [{name: 'Alina', id: '3'}, {name: 'Alex', id: '4'}],
            isPresent : false,
           },
           {
            caseName: 'case 3',
            date: '2021-05-4',
            id: '126',
            user: [],
            isPresent : true,
           },
        ]

And my task is to get a list of IDs from array of objects, but i need ID only from those objecrs which have isPresent as true.
So i need [‘123’, ‘124’].

I could use a loops and conditions and so on. But i wondering is it possible to do with one line ? Something like this:

employees.filter(item => { return item.isPresent === true }))

But i need only IDs not whole objects.

Same element is more than one time then it will return true otherwise it will be false

If the same element is more than one time then it will return true otherwise it will be false.
and push the return value data in output.

var array = [
  { id: 1, value: 10 },
  { id: 2, value: 10 },
  { id: 3, value: 10 },
  { id: 4, value: 56 },
  { id: 5, value: 56 }
]

Output will be like this

var output = [
  { id: 1, value: 10, matched: true },
  { id: 2, value: 10, matched: false },
  { id: 3, value: 10, matched: false },
  { id: 4, value: 56, matched: true },
  { id: 5, value: 56, matched: false }
]

how webRTC peerconnection totalAudioEnergy check

I am working on a project using webRTC API. Check the speaking status of the participant using the totalAudioEnergy property in the peerConnection’s stats object. The totalAudioEnergy property exists in chrome, but the totalAudioEnergy property itself does not exist in safari 15 version on macOS. If you know a solution please help

pc.getStats().then(stats=>{
    stats.forEach(res=>{
        if(res.type == 'media-source'){
            console.log(res)
        }
    })
})

Vue Error: Uncaught (in promise) TypeError cannot read properties of null (reading ‘Address’)

there is an error on clicking on the map is triggered in, time. arrives in Promise, null. Explain why this is happening? Thank you in advance:

onMapClick(e) {
    if (e.latlng) {
    this.post("/api/MapObjectItem/GetObjectInfoByLatLng", {
      Lat: e.latlng.lat,
      Lng: e.latlng.lng
    }).then(result => {
      if (this.jkh.isCreateEvent) {
        this.jkh.selectedMessage = {
          Address: result.Address,
          Lat: result.Lat,
          Lon: result.Lng,
          UsersDataID: this.$auth.user.Id,
          ObjectID: result.Id,
          ToPublish: false
        };
        this.$refs.map.mapObject.setView([result.Lat, result.Lng], 18);
        this.showDetails();
      } else {
        this.obj = result;
        this.changeView();
      }
    });
  }

This Error Promise

how to get value of selected datalist

how do get value of datalist by selection of country. can i get value by onchange?

    <datalist id="countrydata" onchange="fun(this);">
     <option value="Afghanistan">Afghanistan</option>
     <option value="Åland Islands">Åland Islands</option>
     <option value="Albania">Albania</option>
     <option value="India">India</option>
   </datalist>
<label for="country">country</label>
<input type="text"
  list="countrydata"
  id="country" name="country"
  size="50"
  autocomplete="off" />
<script>
    function fun(el){
        var x = document.getElementById('countrydata').value;
        alert(x)
    }
 </script>

Javascript function toLocaleString not working

Following code toLocalString method converting to local date time but in server not able to convert
var utcdatetime=new Date(Date.UTC(fromYear, fromMonth – 1, fromDay)).toLocaleString();
output in server: Tuesday, December 12, 2021 7:00:00 PM
Out put in Local machine: ‎12‎/‎13‎/‎2021‎ ‎4‎:‎00‎:‎00‎ ‎PM.
Desired out is as as shown in the local server.

React Js, My componet is only updating the first time I click row in my list

I have a list, when I click it I want a detail view, and it works the first time but when i click a new row in my list my detail component is not updating. I’m new to this. How to an update every time I click a object in my list.
My detail component called “UpdateSupp” code:

import { useState, useEffect } from "react"
const UpdateSupp = ({ onAdd, _AssNr, _SuppName, _TurnOver12M }) => {
    const [AssNr, setAssNr] = useState('')
    const [SuppName, setSuppName] = useState('')
    const [TurnOver12M, setTurnOver12M] = useState('')

    useEffect(() => {
        const RunAtChange = async () => {
            setAssNr(_AssNr)
            setSuppName(_SuppName)
            setTurnOver12M(_TurnOver12M)
            console.log(`_AssNr =  ${_AssNr}`)
        }
        RunAtChange()
      }, [])

    const onSubmitUppSupp = (e) => {
        e.preventDefault()    
       onAdd({AssNr, SuppName, TurnOver12M})
    }
 
    return (      
        <form className='add-form' onSubmit={ onSubmitUppSupp }>
    
            <div className='form-control'>
                    <h2><label>{ SuppName }</label></h2>
                    </div>   
                    <div  className="wrapper-detail">             
                        <div className="form-control">
                            <label>Leverantör ID</label>
                            <input  type='text' value={AssNr} onChange={(e) => setAssNr(e.target.value)} />
                        </div>
                        <div  className="form-control">
                            <label>Över 12M</label>
                            <input id='set12M'  type='text' value={ TurnOver12M } onChange={(e) => setTurnOver12M(e.target.value)} />
                        </div>
                        </div>
            <input type='submit' value='Spara'  className='btn btn-block' />         
        </form>
    )
}

What am I doing wrong? Is there something else than useEffect to us that fires on every update?

is importing entire module is Ok each time?

I am working on angular project and using firebase.
My question is What if I import entire firebase module in each component Vs importing only what I required in that component from firebase module?
Why should I not import entire module each time when I require it ?

MongoDB node.js : Delete a document automatically after 10 seconds

I want to delete a document automatically after 10 seconds of creating It , but I don’t know why my code doesn’t works (Document not deleted after 10 seconds)

const timestamp = new Date().getTime()

await db.collection("admin_msg").insertOne({createdAt : timestamp , expiresIn : timestamp + 10000 });
await db.collection("admin_msg").createIndex({ expireAt: 1}, { expireAfterSeconds: 10 });

Try catch not working when using Axios Post Request

So what I expected from the code below was that when I get any errors in the request it would do a catch exception, but that is not happening, can anyone help me?

      try {

        const user = UsersServices.register({name: name, email: email, password: password})
        redirectToLogin(true)
      } catch (err) {
        setError(true)
      }

This is the POST I’m using

register: params => Api.post('users/register', params)