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

162
Views
Compare text input's value and default value and check if changes has only spaces

User changes the value of that text box.If user want to close form I must check if changes(recent.value)contains only spaces and if not - just close form, but if it has - alert("Do you realy want to exit without saving changes?")

$('.cancel-button').on('click', function () {
    if (recent.value != recent.defaultValue) {
        // if changes I must check - if this changes contains only spaces
    }
});
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Look at below method isSpaceEqual, which removes spaces in data before comparing, returns true when the change is only spaces.

function isSpaceEqual(value1, value2) {
    value1 = String(value1 || "");
    value2 = String(value2 || "");
    return value1.replace(/[ \r\n]/g, "") === value2.replace(/[ \r\n]/g, "");
}
$('.cancel-button').on('click', function () {
    if (recent.value != recent.defaultValue) {
        // if changes I must check - if this changes contains only spaces
        if(isSpaceEqual(recent.value, recent.defaultValue)) {
            // change is only spaces, new line or carriage return
        } else {
            // actual change
        }
    }
});
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!