I have the following form line:
<input class="form_input" type="text" id="Fname" placeholder="First Name" minlength="2" maxlength="30" onkeyup="restrict('name')" />
And the associated JavaScript code:
function restrict(elem) {
var tf = $('#' + elem)
var rx = new RegExp()
if (elem === 'email') {
rx = /[^a-z0-9@_.-]/gi
} else if (elem === 'username') {
rx = /[^a-z0-9]/gi
} else if (elem === 'phone') {
rx = /[0-9()-]/gi
} else if (elem === 'address') {
rx = /[^a-z0-9_.,-]/gi
} else if (elem === 'city') {
rx = /[^a-z.-]/gi
} else if (elem === 'name') {
rx = /[^a-z.-]/gi
}
tf.val(tf.val().replace(rx, ''))
}
When I try and run the code I get the following error and I can't seem to figure out why after reviewing it many times...
TypeError: tf.val(...) is undefined
Yet everything is defined, so I'm really puzzled.
Thanks for any help! :)