The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Issue with input field

  • This topic is empty.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
  • #151220

    Hi, everyone. Have some problem, don’t know how to solve. I’m writing small application where I check word on screen with word that was entered in input field, after checking every next word I clears input field with s.inputField.value = “”;, but then after checking I have additional empty string before the entered word:

    "word" === " word" // false

    How I can empty input field in another way. Thanks for advice.


    You could use replace function on the string and get rid off white-space.

    Something like this:


    Thanks, @Alen works like a charm. I can’t find courage to learn RegExp

    I have found second variant, to set input defaultValue to “”.


    @Kuzyo I need to take on RegEx myself. I think it’s essential to any programmer.

    I found to be helpful.


    Thanks for advice. Cheers…

    Brad Metcalf

    We had a weird issue on a clients project where we were looking for a word and would get weirdness involved. (Later turns out it was due to their clients copy and pasting from a Word document.) If the situation could use it (like it is not incredibly too sensitive and you can afford to be lax) then indexOf is a viable work around until you find a better solution.

    MDN indexOf Documentation

    MDN indexOf Prototype (Adding support to older browsers…)


    What is the actual application? Are you using this as a challenge (e.g., like a captcha)? Or are you just looking for a particular word in a larger string of input?

    If it’s a challenge, I would argue that it should fail.

    “word” is not the same as ” word”.

    If you’re just looking for a particular word, then use a regex. They’re not scary, and your case is very simple:

    /\bword\b/.test( ' word' );

    it happened

Viewing 7 posts - 1 through 7 (of 7 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.