Question : Inserting a Carriage Return in a Javascript Function

Hi,

I'm hoping somebody might be able to shed some light on this for me.

I'm using a master page and content pages. In the master page I have the return key set to act as tab. This is coded in the tag(see code below).

My problem is that on some of the content pages there are multiline textboxes. I want to be able to create a new line in these using the return key.

At the moment I have stopped the cursor from tabbing out of the mulitline box when I press return. I have done this using a javascript function (see code below). When I step through my javascript it appears that the carriage return is being added. I suspect this because when I read the value of the variable after it has passed through the code, I see a square box has been appended to the text. However when I run my code the cursor remains directly after what I have just typed.

I have tried using \n, \r and \n\r. When I used the last one, there were two boxes appended to my variable's value.

Any help on this would be appreciated.

Please see my code
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
//This is what I have in my  tag in the master page
//this is what makes the return key act as tab
onkeydown="if (event.keyCode==13) {event.keyCode=9; return event.keyCode }">
 
//this is the multiline textbox I want to overwrite this on
//I want to be able to press return to create a new line in this box instead of tab

 
//This is the javascript function I am calling
 
function Keydown(value)
{
if (event.keyCode==13) {value = value+ "\n";event.returnValue = false;}
}
Open in New Window Select All

Answer : Inserting a Carriage Return in a Javascript Function

I am not sure what is going wrong, I can't test it properly at home.

Perhaps you could try this instead:

1:
2:
3:
4:
5:
6:

 
//Keydown function is no longer needed; cancelBubble prevents the keydown event from reaching the event you have on the 
Open in New Window Select All
Random Solutions  
 
programming4us programming4us