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

74
Views
jQuery event not attaching to the input field

I have a field called as cellphoneDetails, I am trying to attach an invalid event to it, but it is not attaching the event to it

$(document).ready(function(e) {
  var x = document.getElementById("contactEditForm");

  if (x.addEventListener) {
    var error = 0;
    alert('bingo');
    x.addEventListener("submit", function(e) {
        alert('test test');
        $("##CellphoneDetails").on("invalid", function() {
          alert($(this).val());
          error = 1;
          if ($(this).val() != '') {
            $(this).focus();
            $("##cellValidDetails").css('display', 'block');
          }
        });
      }
    }
  });

the HTML has the pattern added to it which validates if the value is entered, it should be a valid cellphone number else if its empty, do not validate it and move ahead

but due to some issue, the event is not attaching to the submit call and making a mess

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

First thing I noticed is that it should be $("#CellphoneDetails"), not $("##CellphoneDetails"), and $("#cellValidDetails") instead of $("##cellValidDetails").

To target and ID, you only need one #.

Also, I believe (x.addEventListener) will always be undefined.

You have a mix of JS and jQuery, I'd suggest just using one or the other primarily.

about 4 years ago · Juan Pablo Isaza 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!