jQuery - Keyboard Enter to behave as a - click on a label button?
<p>I have some sort of a jquery chat at one specific PHP page. Of course, bellow that chat area there is an input field (jquery form), and after you click on a label id button, jQuery gets your words, username, stores data into MySql and reloads chat again. Funny lightweight and neat. Reason no1 why you must love jquery.</p>

<p>Anyway, most important to say, that "button" is not submit button - its a "label id" button.</p>

<p>Thats quite okay, but when you get hot into that chat, and you suddenly press enter, instead you click on a label button - PHP page just refreshes and does nothing with data what makes everyone crazy. </p>

<p>So, any hot tip how to send keyboard enter as a click on that label id button?</p>

<hr>

<p><strong>UPDATE:</strong></p>

<pre><code>&lt;form id="chav_box_in" style="padding:0px;margin:0px;" action="" method="post"&gt;
      &lt;div class="chav_level" valign="top"&gt;&lt;input type="hidden" id="chav_in" name="chav_in" value="'.$categoryid.'" /&gt;
      ' . $lg['your_nick'] . ':&amp;nbsp;&amp;nbsp;';
    if($userinfo['loggedin'])
    {
        if($getnamen = $DB-&gt;query_first("SELECT userid, jur_name FROM " . TABLE_PREFIX . "users WHERE userid = '".$userinfo['userid']."'"))
        {
        echo '&lt;input type="hidden" id="chav_username" name="chav_username" value="'.$getnamen['jur_name'].'" /&gt;&lt;span class="chav_name"&gt;'.$getnamen['jur_name'].'&lt;/span&gt;';
        }
        else
        {
    echo '&lt;input type="hidden" id="chav_username" name="chav_username" value="'.$getnamen['userid'].'" /&gt;&lt;span class="chav_name"&gt;Registered undefined ('.$getnamen['userid'].')&lt;/span&gt;';
        }
    echo '&lt;input type="hidden" id="chav_lag" name="chav_lag" value="1" /&gt;';
    }

    else // unergs
    {
        if($nemere) //cookieid
        {
        echo '&lt;input type="hidden" id="chav_username" name="chav_username" value="'.$nemere.'" /&gt;&lt;span class="chav_name"&gt;'.$nemere.'&lt;/span&gt;';
        }
        else   //nov upisivac
        {
        echo '&lt;input type="text" size="' . $inputsize . '" id="chav_username" name="chav_username" value="" /&gt;';
        }
    }

echo '&amp;nbsp;&amp;nbsp;' . $lg['occ_place'] . ':&amp;nbsp;';

// ##########
    if($categoryid == 6)
    {
    echo '&lt;input type="text" size="' . $inputsize . '" id="chav_sub" name="chav_sub" value="" /&gt;&lt;/div&gt;';
    }
    else
    {
    echo '&lt;input type="hidden" id="chav_sub" name="chav_sub" value="'.$url_places_name.'" /&gt;&lt;span class="chav_name"&gt;'.$url_places_name.'&lt;/span&gt;&lt;/div&gt;';
    }


    echo '&lt;div class="chav_level"&gt;' . $lg['chav_input'] . '&amp;nbsp;&amp;nbsp;&lt;input type="text" size="' . ($inputsize*5) . '" id="wm1" name="wm1" value="" /&gt;
     &amp;nbsp;&lt;label id="shareButton1" class="enter" style="display:inline;float:right;"&gt;' . $lg['publish'] . '&lt;/label&gt;&lt;/div&gt;';


    echo '&lt;/form&gt;
</code></pre>

<p>Now, when I enter something in that input field and press enter, page refreshes.. no mind for a mess im cleaning it out.. AND query</p>

<pre><code>$(function () {
$('chav_box_in').keypress(function(e) { // Attach the form handler to the keypress event
    if (e.keyCode == 13) { // If the the enter key was pressed.
        $('#shareButton1').click(); // Trigger the button(elementId) click event.
        return e.preventDefault(); // Prevent the form submit.
    }
});
});
</code></pre>
