Problem with android and scrolling with <input textarea


Joined
May 18, 2022
Messages
3
Reaction score
0
we have a problem with newer devices posting comments in the news form with google chrome. If the news is just one everything works fine when you press enter with your phone, but when there are several news and when you press enter just start scrolling to the latest news and it only works then. I think the problem is in javascript, so i want to ask you for help. Thanks.

This is javascript;

JavaScript:
newsReply = function(event, id, item) {
    if(event.keyCode == 13 && event.shiftKey == 0){
        var content = $(item).val();
        var replyTo = id;
        if (/^\s+$/.test(content) || content == ''){
            return false;
        }
        if(content.length > 1000){
            alert("text is too long");
        }
        else {
            $(item).val('');
            if(repNews == 0){
                repNews = 1;
                $.ajax({
                    url: "system/action_news.php",
                    type: "post",
                    cache: false,
                    dataType: 'json',
                    data: {
                        content: content,
                        reply_news: replyTo,
                        token: utk
                    },
                    success: function(response){
                        if(response.code == 1) {
                            $('.ncmtbox'+replyTo).prepend(response.data);
                            nrepCount(id, response.total);
                            repNews = 0;
                        }
                        else {
                            repNews = 0;
                            return false;
                        }
                    },
                    error: function(){
                        repNews = 0;
                        return false;
                    }
                });
            }
            else {
                return false;
            }
        }
    }
    else {
        return false;
    }
}

this is our html;

HTML:
 <div class="tpad10 reply_post">
            <input onkeydown="newsReply(event, <?php echo $boom['id']; ?>, this);" maxlength="500" placeholder="<?php echo $lang['comment_here']; ?>" class="add_comment full_input">
        </div>
 
Ad

Advertisements

Joined
Mar 11, 2022
Messages
82
Reaction score
8
Can't see anything wrong with newsReply. What is nrepCount? And prepend?

Where is the part where your input element blurs? (When does the Android keyboard disappear?)
 
Joined
May 18, 2022
Messages
3
Reaction score
0
This is a news system built into the menu, which works by pressing Enter, but in Android chrome just by pressing enter it starts jumping to other input forms until it reaches the last one and there the comments already work. That is, he jumps until he reaches the last one and i don't know where the problem is. There is no such problem with Opera and Mozilla, besides I read that KeyCode is deprecated..

nrepCount is numbers of currently comments per new.
 
Joined
Mar 11, 2022
Messages
82
Reaction score
8
No, keyCode isn't depreciated yet.

Doesn't make any sence. Maybe it's the wrong jquery part you have postet. Did you wrote this code by yourself, or is it a "kind of" open source jquery menu?

In your code is no "tabbing or jumping" to other input elements included. So the issue is somewhere else.

The only thing that comes to my mind on this portion of code is the event handling itself.

It's just an idea but try
Code:
if(!event){event=window.event}
 if(event.keyCode == 13){

leave shiftKey out, because it's not needed for return but may cause issues for some mobiles.

But i doubt that that will help you. What exactly happens after the ajax call? Is there any related and executed javascript on action_news.php?


EDIT: And add a type="text" to your input element.
 
Ad

Advertisements

Joined
Mar 11, 2022
Messages
82
Reaction score
8
Well. One reason why i hate jquery. Unfortunately i can't help you with JQ. What about a start over with pure js? I could help you with that
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top