Converting form field data to uppercase

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nige

    #1

    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
  • Raul Carrillo Garrido

    #2
    Re: Converting form field data to uppercase

    Maybe this script helps you. Has been taken from The Javascript Source.-



    <!-- 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="javas cript:this.valu e=this.value.to UpperCase();">
    <br>
    <input type="button" value="Ok!">
    </form>
    </center>

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

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

    Metsuke <(^_^)>


    "Nige" <uYYYY@ntlworld .com> escribió en el mensaje
    news:j8jsqv4j20 ikiarou2h2in49r knh8qrmba@4ax.c om...[color=blue]
    > 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[/color]


    Comment

    • VK

      #3
      Re: Converting form field data to uppercase

      document.FormNa me.FieldName.va lue =
      document.FormNa me.FieldName.va lue.toUpperCase ();
      or
      with (document.FormN ame) {
      FieldName.value = FieldName.value .toUpperCase();
      /* all the same, just "cooler" looking and shorter*/
      }


      Comment

      • Elmo Watson

        #4
        Re: Converting form field data to uppercase

        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="Javas cript">
        <!-- Beginning of JavaScript -
        function convcaps(this)
        {
        document.form.t his.value=docum ent.form..this. value.toUpperCa se();
        }
        // - End of JavaScript - -->
        </SCRIPT>

        Then, in the input box:
        <input name="textbox1" type="text" id="textbox1"
        onChange="convc aps(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" <rcarrillo@cole ccionalo.com> wrote in message
        news:0ssrb.9574 83$uj6.2399631@ telenews.teleli ne.es...[color=blue]
        > 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="javas cript:this.valu e=this.value.to UpperCase();">
        > <br>
        > <input type="button" value="Ok!">
        > </form>
        > </center>
        >
        > <p><center>
        > <font face="arial, helvetica" size="-2">Free JavaScripts provided<br>
        > by <a href="http://javascriptsourc e.com">The JavaScript Source</a></font>
        > </center><p>
        >
        > <!-- Script Size: 0.55 KB -->
        >
        > Metsuke <(^_^)>
        >
        >
        > "Nige" <uYYYY@ntlworld .com> escribió en el mensaje
        > news:j8jsqv4j20 ikiarou2h2in49r knh8qrmba@4ax.c om...[color=green]
        > > 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[/color]
        >
        >[/color]



        Comment

        • Lasse Reichstein Nielsen

          #5
          Re: Converting form field data to uppercase

          "Elmo Watson" <sputnik75043@y ahoo.com> writes:
          [color=blue]
          > <SCRIPT LANGUAGE="Javas cript">
          > <!-- Beginning of JavaScript -
          > function convcaps(this)
          > {
          > document.form.t his.value=docum ent.form..this. value.toUpperCa se();
          > }
          > // - End of JavaScript - -->
          > </SCRIPT>[/color]
          [color=blue]
          > What am I doing wrong here?[/color]

          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 "variableNa me" since "this" is not
          legal. It contains a string with the name of a property of the form.
          You then write.
          document.form.v ariableName.val ue
          This finds the property with the name "variableNa me" 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 - lrn@hotpop.com
          DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
          'Faith without judgement merely degrades the spirit divine.'

          Comment

          • Thomas 'PointedEars' Lahn

            #6
            Re: Converting form field data to uppercase

            Lasse Reichstein Nielsen wrote:
            [color=blue]
            > 1) "this" is a keyword in Javascript, you can't use it as a variable.[/color]

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


            PointedEars

            Comment

            • Richard Cornford

              #7
              Re: Converting form field data to uppercase

              "Thomas 'PointedEars' Lahn" <PointedEars@we b.de> wrote in message
              news:bp3kb7$1ii aui$3@ID-107532.news.uni-berlin.de...[color=blue][color=green]
              >>1) "this" is a keyword in Javascript, you can't use it as a variable.[/color]
              >
              >More, `this' is a special operator and (therefore) a reserved word.[/color]

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

              Richard.


              Comment

              • Thomas 'PointedEars' Lahn

                #8
                Re: Converting form field data to uppercase

                Richard Cornford wrote:
                [color=blue]
                > "Thomas 'PointedEars' Lahn" <PointedEars@we b.de> wrote in message
                > news:bp3kb7$1ii aui$3@ID-107532.news.uni-berlin.de...[color=green][color=darkred]
                >>>1) "this" is a keyword in Javascript, you can't use it as a variable.[/color]
                >>
                >>More, `this' is a special operator and (therefore) a reserved word.[/color]
                >
                > That would explain why ECMA 262 Section 7.5.2 lists "this" specifically
                > under the heading "keywords".[/color]

                -v


                PointedEars

                Comment

                Working...