comparison operators in js.erb files
I have a file called new.js.erb that contains this line:
if( $('#user_password').val().length < 6 )
For some reason, the less-than symbol breaks down the whole file. I think Rails is seeing the < symbol as the beginning of a tag for some reason. I just want to check if the value in the user_password field has a str开发者_开发问答ing length less than 6. Is there a way to do this in jQuery in a js.erb file?
Amazingly, all my Googling and SO searching have not uncovered a solution.
If you need any more information, please don't hesitate to ask for it.
Thank you for any help!
More code for mu (I can guarantee everything above and below this block is working fine):
if( $('#user_password').text().length < 6 )
{
$('form.edit_user').submit();
popup.unload();
$('#send_after_pass').show();
$('#send_after_pass').click(function(e) {
$(this).hide();
$('form.new').submit();
});
else
{
$('#errors').html("Password must be 6 characters or longer.");
}
EDIT: My bad on the bogus quote! Pretend it was never there... That isn't what caused my problem, though.
I don't see any ERB in the code you posted but there is a missing closing brace, your code should look more like this:
if( $('#user_password').text().length < 6 )
{
//...
}
else
{
$('#errors').html("Password must be 6 characters or longer.");
}
Note the closing brace I added above your else
.
Why not try to reverse the condition, like this and see if it is indeed the operator?
if (6 > $('#user_password').val().length)
精彩评论