By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,605 Members | 2,137 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,605 IT Pros & Developers. It's quick & easy.

Script for Text Box

P: 1
I am looking for a script to only allow the user to enter one word into a text box. No spaces, just one word. Is there such a script? Thanks
Sep 8 '06 #1
Share this Question
Share on Google+
2 Replies


RamananKalirajan
100+
P: 607
I am looking for a script to only allow the user to enter one word into a text box. No spaces, just one word. Is there such a script? Thanks

Hello Sputnam, I think the following code may be useful for you. If any more doubts pls post it. The following code will search for whitespace if it occurs it doesn't allows the user to enter.

[HTML]<html>
<body>
<script type="text/javascript">
function noSpace()
{
var y = document.getElementById('txtBox').value;
if(y.indexOf(" ")==-1)
return true;
else
return false;
}
</script><form>
<input type="text" id="txtBox" onkeypress="return noSpace()" />
</form></html>[/HTML]

Regards
Ramanan Kalirajan
Mar 19 '08 #2

ronverdonk
Expert 2.5K+
P: 4,258
Welcome to The Scripts!

This next code prevents the blank from being typed but continues with other characters
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. function CheckBlank()
  3. {
  4.   if (event.keyCode == 32) {
  5.     return false; }
  6.   else {
  7.     return true;
  8.   }
  9. }
  10. </script>
  11. <input type="text" name="field" onkeydown="return CheckBlank()" />
Ronald
Mar 19 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.