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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating capital letter

Status
Not open for further replies.

benrob82

Programmer
Jul 28, 2005
116
GB
Hi,
Just wondering if its possible to give the first letter of a new word capital letters and the code uses UCase and LCase?

Thanks
 
its actually to do it in the title and I don't think that CSS works for the title
 
What you need is javascript, not asp. Try this:

Code:
<script language="JavaScript" type="text/javascript">
<!--
function capitalize(el) {
	if(!document.layers) {
	el.value = el.value.substring(0,1).toUpperCase() + 
	el.value.substring(1,el.value.length);
}}
//-->
</script>
<head>

<body>
...
...
<input name="fname" type="text" id="fname" onkeypress="capitalize(this)" />
 
i'm not too good with javascript, could you explain slightly?
 
All you need to do is past this part in the <head>
Code:
<script language="JavaScript" type="text/javascript">
<!--
function capitalize(el) {
    if(!document.layers) {
    el.value = el.value.substring(0,1).toUpperCase() + 
    el.value.substring(1,el.value.length);
}}
//-->
</script>
Thats our function, we call it, and pass it stuff. It breaks down the word, changes the first character to a capital letter with 'toUpperCase()' You can use this on any text box.

All you need to do after that is add this to the text box code, or several text boxes
Code:
onkeypress="capitalize(this)"
What that does, on each key press it passes the value you just typed 'this' and does it's magic.
 
thanks candyman but its not text boxes its being used to change the page title
 
I still like the CSS suggestion. I don't know what your title is in, but pretend itis in H1 tags:
Code:
<style type="text/css">
H1{
   text-transofmr: capitalize;
}
</style>

Tada, all done. CSS works for anything in the HTML page that is displayed. Well, unless your using a fairly old browser... :p

-T

barcode_1.gif
 
Oh, in that case you probably need to write a ProperCase type function in your ASP code and call it server-side. There have been several examples posted here to the forums over time (at least one of them by me) as well as tons on the internet. Searching on ProperCase and ASP will probably get you a goodnumber of hits, since that function was available in VB6 and a lot of developers created their own with the sme name for use in VBScript.

-T

barcode_1.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top