Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

371
Views
función que verifica si la validación es verdadera, luego haga esto

Estoy tratando de hacer que esto funcione.

Validación 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 == '') { } 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. '; } }

Quiero que mi función de check verifique si la validation es verdadera y luego cambie el innerHTML de success a You have successfully created an account.

Función check JS:

 function check() { if (validation === true) { document.getElementById('success').innerHTML = 'Your account has been successfully created.'; } }

Sé que está un poco desordenado y admito que todavía soy nuevo en esto.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Una forma común de hacerlo es inicializar un valor booleano en true , si algún campo está vacío o no es válido, asigna false a este valor booleano. Devuelve su valor al final de la función de validación.

 function check() { //no need to check === true here if (validation()) { document.getElementById('success').innerHTML = 'Your account has been successfully created.'; } } function validation() { let isValid = true; var fname = document.getElementById('fname').value; if (fname == '') { document.getElementById('fn').innerHTML = 'Please enter first name.'; isValid = false; } var lname = document.getElementById('lname').value; if (lname == '') { document.getElementById('ln').innerHTML = 'Please enter last name.'; isValid = false; } var birth = document.getElementById('birthdate').value; if (birth == '') { document.getElementById('bday').innerHTML = 'Please enter birthdate.'; isValid = false; } var gender = document.getElementById('gender').value; if (gender == 'select') { document.getElementById('gndr').innerHTML = 'Please choose your gender.'; isValid = false; } var username = document.getElementById('username').value; if (username == '') { document.getElementById('usr').innerHTML = 'Please enter username.'; isValid = false; } var email = document.getElementById('email').value; if (email == '') { isValid = false; } var econf = document.getElementById('econf').value; if (econf == '') { document.getElementById('rt-eml').innerHTML = 'Please confirm your email.'; isValid = false; } if (econf != email) { document.getElementById('rt-eml').innerHTML = 'Email did not match.'; isValid = false; } var password = document.getElementById('password').value; if (password == '') { document.getElementById('pass').innerHTML = 'Please enter password.'; isValid = false; } var pconf = document.getElementById('pconf').value; if (pconf == '') { document.getElementById('rt-pass').innerHTML = 'Please confirm your password.'; isValid = false; } if (pconf != password) { document.getElementById('rt-pass').innerHTML = 'Password did not match. Try again. '; isValid = false; } return isValid; }
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!