faqts : Computers : Programming : Languages : JavaScript : Forms

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

1 of 7 people (14%) answered Yes
Recently 1 of 7 people (14%) answered Yes

Entry

Is it possible to change the format of text within a text feild without writing HTML tags?

Jul 25th, 2003 07:40
Kasey, Barry Girsh,


I assume the reason for this question is that you want to save the 
time and hassle of typing a bunch of HTML tags inside <form> to 
achieve the desired text effect.
You can format the text quite easily by inserting a single-line 
stylesheet. While still technically considered HTML, it will get you 
away from having to code each tag individually.
Here's an example:
<style type="text/css" media="screen">
<!--
.formtext{font-family:verdana,sans-serif; font-weight:normal; font-
size:11px;}
-->
</style>
Just place this between <head> and </head> in your document. Then, 
when creating the form, designate each text input area as 
class="formtext" ...
i.e.,
<input type="text" class="formtext" size="20" name="fieldname" />
You can play around with the variables in the stylesheet to achieve 
the text formatting of your choice.
If you want to perform the same action in javascript, the best option 
I can give is to encase the entire stylesheet inside a call to 
document.write(). I don't know what this would accomplish for you, 
however, as it seems to add unnecessary size to the HTML file.
i.e.,
<script type="text/JavaScript">
<!--
document.write("<style><!--.formtext{font-family:verdana,sans-serif; 
font-weight:normal; font-size:11px;}--></style>");
// -->
</script>