News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Clean it up?

Started by fobnicat, October 03, 2014, 12:03:13 AM

Previous topic - Next topic

fobnicat

Hi all,

My users requested the ability to submit their input to shoutbox through hitting the [ Enter ] key rather than clicking [ Submit ]

I did this:

echo '
<textarea onkeyup="if (event.keyCode == 13) { this.form.submit(); return false; }" name="shout"  rows="3" cols="30" style="width: 96%"></textarea>
<br />
<input type="submit" value="', $txt['ezp_shoutbox_add_shout'], '" />

</form>';
}


But it seems there should be a cleaner way to do it...  When using this method, the cursor still moves down a line giving the impression that it did not take, then after a moment it submits and the page reloads.  Any thoughts?

TehCraw

If you don't care about having more than one line of text, you could change the textarea to a field and just let the form submit itself as normal when you press enter.
Any fool can write code that a computer can understand. Good programmers write code that humans can understand. - Martin Fowler

Night09

keydown not up. your telling it not to submit until the key comes up so it types a line.

Aquilo

<form action=""><textarea onkeyDown="if (!event.shiftKey && event.keyCode == 13) { this.form.submit(); return false; }" name="shout"  rows="3" cols="30" style="width: 96%"></textarea></form>

This would allow more than 1 line.

facebook with submit comments on pressing enter but will let you add new lines as long as you press shift+enter. i like that so thought I'd suggest it!  8)

I love doing silly testing on jsfiddle, enter will give an alert in this... lol
http://jsfiddle.net/8h50hyo9/

Advertisement: