469,271 Members | 1,785 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,271 developers. It's quick & easy.

Converting form field data to uppercase

Is it possible to convert an item of form field data to uppercase using
the toUpperCase() method?

What I'm really asking is, how do I reference the data item?
--
Nige

Please replace YYYY with the current year
ille quis mortem cum maximus ludos, vincat
Jul 20 '05 #1
7 24526
Maybe this script helps you. Has been taken from The Javascript Source.-
http://javascriptsource.com
<!-- ONE STEP TO INSTALL ALL UPPER CASE:

1. Copy the coding into the BODY of your HTML document -->

<!-- STEP ONE: Paste this code into the BODY of your HTML document -->

<BODY>

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<center>
<form name="capsform">
<input type="text" name="caps" size=40 value=""
onChange="javascript:this.value=this.value.toUpper Case();">
<br>
<input type="button" value="Ok!">
</form>
</center>

<p><center>
<font face="arial, helvetica" size="-2">Free JavaScripts provided<br>
by <a href="http://javascriptsource.com">The JavaScript Source</a></font>
</center><p>

<!-- Script Size: 0.55 KB -->

Metsuke <(^_^)>
"Nige" <uY***@ntlworld.com> escribió en el mensaje
news:j8********************************@4ax.com...
Is it possible to convert an item of form field data to uppercase using
the toUpperCase() method?

What I'm really asking is, how do I reference the data item?
--
Nige

Please replace YYYY with the current year
ille quis mortem cum maximus ludos, vincat

Jul 20 '05 #2
VK
document.FormName.FieldName.value =
document.FormName.FieldName.value.toUpperCase();
or
with (document.FormName) {
FieldName.value = FieldName.value.toUpperCase();
/* all the same, just "cooler" looking and shorter*/
}
Jul 20 '05 #3
This works well for me, but what I'm trying to do is create a function that
does this so I can use the same thing in all form fields and I just can't
get it....
I've tried various forms of what you see below and it never works:
<SCRIPT LANGUAGE="Javascript">
<!-- Beginning of JavaScript -
function convcaps(this)
{
document.form.this.value=document.form..this.value .toUpperCase();
}
// - End of JavaScript - -->
</SCRIPT>

Then, in the input box:
<input name="textbox1" type="text" id="textbox1"
onChange="convcaps(textbox1);">

I keep getting an 'Expected Identifier' error in the main line of the
function - -

What am I doing wrong here?

Thanks.

"Raul Carrillo Garrido" <rc*******@coleccionalo.com> wrote in message
news:0s**********************@telenews.teleline.es ...
Maybe this script helps you. Has been taken from The Javascript Source.-
http://javascriptsource.com
<!-- ONE STEP TO INSTALL ALL UPPER CASE:

1. Copy the coding into the BODY of your HTML document -->

<!-- STEP ONE: Paste this code into the BODY of your HTML document -->

<BODY>

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<center>
<form name="capsform">
<input type="text" name="caps" size=40 value=""
onChange="javascript:this.value=this.value.toUpper Case();">
<br>
<input type="button" value="Ok!">
</form>
</center>

<p><center>
<font face="arial, helvetica" size="-2">Free JavaScripts provided<br>
by <a href="http://javascriptsource.com">The JavaScript Source</a></font>
</center><p>

<!-- Script Size: 0.55 KB -->

Metsuke <(^_^)>
"Nige" <uY***@ntlworld.com> escribió en el mensaje
news:j8********************************@4ax.com...
Is it possible to convert an item of form field data to uppercase using
the toUpperCase() method?

What I'm really asking is, how do I reference the data item?
--
Nige

Please replace YYYY with the current year
ille quis mortem cum maximus ludos, vincat



Jul 20 '05 #4
"Elmo Watson" <sp**********@yahoo.com> writes:
<SCRIPT LANGUAGE="Javascript">
<!-- Beginning of JavaScript -
function convcaps(this)
{
document.form.this.value=document.form..this.value .toUpperCase();
}
// - End of JavaScript - -->
</SCRIPT> What am I doing wrong here?


Top posting. Please trim your quotes instead of including the entire
message you respond to.

In HTML 4, the type attribute is required on the script tag. The
recommended way to start a script element is:
<script type="text/javascript">

You don't need the <!-- line.

And, the important errors:

1) "this" is a keyword in Javascript, you can't use it as a variable.

2) you have a variable, call it "variableName" since "this" is not
legal. It contains a string with the name of a property of the form.
You then write.
document.form.variableName.value
This finds the property with the name "variableName" in the form, not
the one with name that is in the string that variableName refers to.
To use a variable to look up a property, you must use square brackets:
document.form[variableName].value
<URL:http://jibbering.com/faq/#FAQ4_39>

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #5
Lasse Reichstein Nielsen wrote:
1) "this" is a keyword in Javascript, you can't use it as a variable.


More, `this' is a special operator and (therefore) a reserved word.
PointedEars
Jul 20 '05 #6
"Thomas 'PointedEars' Lahn" <Po*********@web.de> wrote in message
news:bp*************@ID-107532.news.uni-berlin.de...
1) "this" is a keyword in Javascript, you can't use it as a variable.


More, `this' is a special operator and (therefore) a reserved word.


That would explain why ECMA 262 Section 7.5.2 lists "this" specifically
under the heading "keywords".

Richard.
Jul 20 '05 #7
Richard Cornford wrote:
"Thomas 'PointedEars' Lahn" <Po*********@web.de> wrote in message
news:bp*************@ID-107532.news.uni-berlin.de...
1) "this" is a keyword in Javascript, you can't use it as a variable.


More, `this' is a special operator and (therefore) a reserved word.


That would explain why ECMA 262 Section 7.5.2 lists "this" specifically
under the heading "keywords".


-v
PointedEars
Jul 20 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by nntp-service.ohio-state.edu | last post: by
3 posts views Thread by Tony | last post: by
2 posts views Thread by Yeah | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.