JSFiddle - React, Tailwind, and code Playground

by azamalvi

HTML

<div class="submitComment" id="1">
    <form>text 1
        <textarea class="text" name="message" style=" margin-top:-12px; height:25px; resize:none;margin-left:10px;width:300px;"></textarea>
        <div style="display:none">
            <input value="Submit Comment" type="submit" id='go1'>
        </div>
    </form>
</div>
</br>
<div class="submitComment" id="2">
    <form>text 2
        <textarea class="text" name="message" style=" margin-top:-12px; height:25px; resize:none;margin-left:10px;width:300px;"></textarea>
        <div style="display:none">
            <input value="Submit Comment" type="submit" id='go2'>
        </div>
    </form>
</div>
</br>
</br>
    select any inputbox and press enter

JavaScript

$(document).ready(function () {

    $('.submitComment').submit(function () {
     //it will call when enter is pressed 
   });
    
    /*$('input').click(function() {
        var id=$(this).attr('id');
            alert(id);  
    });*/
    
    $(".text").bind("keydown", function (event) {
        // track enter key
        var keycode = (event.keyCode ? event.keyCode : (event.which ? event.which : event.charCode));
        if (keycode == 13) { // keycode for enter key
            // force the 'Enter Key' to implicitly click the Update button
            var id=$(this).attr('id');
            alert(id);            
            //document.getElementById('go1').click();
            (id).click();
            return false;
        } else {
            return true;
        }
    });
});