Stop Enters

JavaScript related questions should go here.
Post Reply
unemployment
Posts: 165
Joined: Fri May 06, 2011 5:02 pm

Stop Enters

Post by unemployment »

I have a textarea and I need to stop the line breaks from happening when enter is pressed. Why doesn't return false work?

[syntax=javascript]
if (is_key(event, 13) && (with_field.value.length > 1)){
var search_list_ele_array = new Array();
var search_list_ele_array = document.getElementById('with_auto').getElementsByTagName('li');

for (j=0; j<search_list_ele_array.length; j++) {

if ((search_list_ele_array[j].className == 'user list_hover') || (search_list_ele_array[j].className == 'comp list_hover') || (search_list_ele_array[j].className == 'blog list_hover')){
var link = search_list_ele_array[j].getElementsByTagName('a');
user_add(link[0], search);
}
}
return false;
}
[/syntax]
Torniquet
Posts: 52
Joined: Sun Jun 19, 2011 8:10 am
Contact:

Re: Stop Enters

Post by Torniquet »

if you don't want multilines why are you using a text area?

i haven't tried achieving this, but try using substr. textbox value = substr(0,textbox.value - 1)

just a quick thought off the top of my head.
unemployment
Posts: 165
Joined: Fri May 06, 2011 5:02 pm

Re: Stop Enters

Post by unemployment »

Torniquet wrote:if you don't want multilines why are you using a text area?

i haven't tried achieving this, but try using substr. textbox value = substr(0,textbox.value - 1)

just a quick thought off the top of my head.


Your quick thought might be good in theory but it is not correct. If I wrote "Hi am really cool [enter]", then that would erase everything I just wrote which is not what I want to do. I want to disable enters, NOT trim them. P.s. I just need a text area... too long to describe.
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Stop Enters

Post by jacek »

I think you would have use that method, the code should have been

[syntax=javascript]textbox.value = textbox.value.substr(0, textbox.value.length - 1);[/syntax]
Image
unemployment
Posts: 165
Joined: Fri May 06, 2011 5:02 pm

Re: Stop Enters

Post by unemployment »

jacek wrote:I think you would have use that method, the code should have been

[syntax=javascript]textbox.value = textbox.value.substr(0, textbox.value.length - 1);[/syntax]


Hmm that actually still didn't work for me.

I need to you use...

[syntax=javascript]
with_field.onkeypress = function(event){
if (is_key(event, 13) === true){
return false;
}
}[/syntax]
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Stop Enters

Post by jacek »

so what error are you getting now ? :?
Image
unemployment
Posts: 165
Joined: Fri May 06, 2011 5:02 pm

Re: Stop Enters

Post by unemployment »

jacek wrote:so what error are you getting now ? :?


Whoops I meant that the thread above was what I needed to use. It works now.
Post Reply