|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Text Area - submit form when user strikes Enter button
Hi,
I have a form with a text area. If a user strikes the Enter button on their keyboard, this effects a carriage return within the text area. Rather than effecting a carriage return within the text area, I want the form to submit. Can someone please tell me whether this is possible and (if so) how it can be achieved? Just in case it's relevant, I will mention that I'm using a function to check that all the characters entered into the text area are permitted. I'm permitting A-Z, 0-9, comma, full-stop/period, space, and underscore. This works fine. Here's the code: Code:
<%
Function IsAlphaNumericPlusCFS_(sString)
'0-9 , A-Z , comma , full-stop, space, underscore
Dim nChar, i
IsAlphaNumericPlusCFS_ = True
For i = 1 To Len(sString)
nChar = Asc(LCase(Mid(sString, i, 1)))
If not ((nChar = 32 or nChar = 44 or nChar = 46) or (nChar > 47 And nChar < 58) or (nChar = 95) or (nChar > 96 And nChar < 123)) Then
IsAlphaNumericPlusCFS_ = False
Exit For
End If
Next
End Function
%>
If it can be achieved, I'll add nChar=13 to the list of permitted characters. Thanks. |
|
#2
|
||||
|
||||
|
Hi,
It is possible to use javascript to trap the keypress and act on Char(13) if the user hits enter. The issue you will have though is that javascript can be disabled in the client's browser, rendering your code useless. Code:
<html>
<head>
<script>
function handleKeyPress(e)
{
if (!e) e = window.event;
if (e && e.keyCode == 13)
{
document.myForm.submit();
}
}
</script>
</head>
<body>
<form name="myForm" method="post" action="test.asp">
<textarea name="myTextArea" onkeypress="return handleKeyPress(event);"></textarea>
</form>
</body>
</html>
|
|
#3
|
|||
|
|||
|
Hi SOS,
Thanks for the code and the advice. Quote:
All users will be warned that only the previously mentioned characters are permitted so I don't think that I need to warn them about Enter being ignored. Could you possibly tell me if there is any practical reason why I shouldn't use replace? Thanks again, ff |
|
#4
|
||||
|
||||
|
Quote:
No, I cant think of any reason why you shouldnt use replace. I would always advise against relying upon a javascript to submit your form if you couldnt guarantee that all of the users have javascript enabled. At least using the replace method the form will behave the same for all users. |
|
#5
|
|||
|
|||
|
That's good news, then. Thanks again, SOS.
ff |
![]() |
| Viewing: ASP Free Forums > Programming > ASP Development > Text Area - submit form when user strikes Enter button |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|