Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Text boxes and Javascripts and the < br > tag 1

Status
Not open for further replies.

peter11

Instructor
Mar 16, 2001
334
0
0
US
I am a coldfusion programmer and want to know if there are any javascripts for Text Boxes that:
Will create a <br> tag when a user is typing in a text box and hits the enter key.

If there are not javascripts is there anything else that does this?
 
Hi Peter,

I don't know if you want to add a new blank line to the text the visitor is typing.If it's that way,this sould be work for you:


<html>
<head>
<title>BR PAGE</title>
<script language=&quot;JavaScript&quot;>
<!--
function writeBR()
{
key=event.keyCode;
if(key==13)
{
document.myform.textbox.value=document.myform.textbox.value+' ';
}
}
//-->
</script>
</head>

<body>

<form name=&quot;myform&quot;>
<textarea cols=&quot;20&quot; rows=&quot;5&quot; name=&quot;textbox&quot; onKeyDown=&quot;writeBR()&quot;></textarea>
<br>
<input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Submit&quot;>
&nbsp;&nbsp;
<input type=&quot;reset&quot; name=&quot;reset&quot; value=&quot;Reset&quot;>
</form>
</body>
</html>

If you want to specify the 'cols' attribute let's say to 20,then in the function you must add 20 blank spaces in the section:
document.myform.textbox.value=document.myform.textbox.value+' ';
(here you put 20 blank spaces if you have 20 cols in your text box).

I hope this helps.

Kindest Regards

Alexfusion
 
function checkKey(obj) {
if(event.keyCode == 13) {
document.execCommand(&quot;Paste&quot;,false,&quot;<br>&quot;)
obj.focus();
}
}

then add onkeyUp=&quot;checkKey(this)&quot; to any text boxes you want to check in. it will add the acctual code for a br (only works in msie)

i'm not sure if ns supports ranges or not or you might be able to use them to make a cross browser version.
 
All this infor is great. But here is another text area question:
I users to be able to enter number signs, single quotemarks, double quotemarks and ampersands. Must they use HTML Character codes or Does Cold Fusion have an answer to this?

BTW I want them to be able us modify text with HTML code as well.

Is there a good book out there on this stuff.
 
cold fusion should handle them all though since they are in a variable when you'll be using them.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top