var $one = $('#oneClueShow');
var x = $("#clueOneInput").find('input[type=text]').val();
if(x == 'D R' || x == 'd r'|| x == 'D r'|| x == 'd R'|| x == 'd'|| x == 'r' || x == 'd R' || x == 'T A')
Above is a snippet of java/ I have. What it does is takes an input -- then checks for a match. The bug I'm looking to resolve is if there are spaces after or before it isn't recognized.
For example within the input someone can type 'D R' no problem. If a space is added like so 'D R ' then it no longer recognizes the input.
Is there something I can do to affect the input to ensure no space before/after prior to button click? I've been looking into replace, but can't seem to get it going.
A reference for what I've been looking at : http://www.w3schools.com/jsref/jsref_replace.asp
You can use $.trim
$.trim(yourstring)
which will allow for cross browser compatibility
In your case it would be
var x = $.trim($("#clueOneInput").find('input[type=text]').val());
Use the trim()
method
Example:
var str = " Hello World! ";
alert(str.trim());
This will output :
Hello World!
var str = " Hello World! ";
alert(str.trim());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With