Capitalize small alphabet

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vikas251074
    New Member
    • Dec 2007
    • 198

    Capitalize small alphabet

    If a user types either small or capital alphabets in <input type="text"/> tag, then it should become all capital. Can this be done using javascript?

    Thanks and regards,
    Vikas
  • veenna
    New Member
    • Dec 2007
    • 65

    #2
    You can use String.toUpperC ase(); to convert string to uppercase.

    Comment

    • vikas251074
      New Member
      • Dec 2007
      • 198

      #3
      I have written as follows.

      Created a function capital() in javascript tag like this

      Code:
      <script type="text/javascript">
      function capital(temp){
        return String.toUpperCase(temp); 
      }
      </script>
      And called this function like this

      Code:
      <td align="left"><input type="text" style="width:250px " name="vlan_name" onchange="return capital(this);"/></td>
      Also I used onblur event in place of onchange event.

      It does not work.

      Thanks and regards,
      Vikas

      Comment

      • veenna
        New Member
        • Dec 2007
        • 65

        #4
        You can use this function

        [CODE=javascript]<script type="text/javascript">
        function capital(temp){
        var str=temp.value
        document.getEle mentById('vlan_ name').value = str.toUpperCase ();
        }
        </script>[/CODE]



        and call function as

        [HTML]<input type="text" style="width:25 0px " name="vlan_name " id="vlan_name" onkeyup="capita l(this);"/>[/HTML]



        thanks

        Veenna
        Last edited by gits; Jun 7 '08, 10:23 AM. Reason: added code tags

        Comment

        • vikas251074
          New Member
          • Dec 2007
          • 198

          #5
          Yes, you are right madam,

          My problem is solved. But this function (capital()) can not be used multiple times for other <input tag>. How can I do this?

          Suppose there are three fields,
          vlan_name, vlan_location, vlan_type.
          Then I want to use capital() in all three cases.

          This line
          document.getEle mentById('vlan_ name').value = str.toUpperCase ();
          makes difficult for using multiple times.

          Thanks and regards
          Vikas

          Comment

          • veenna
            New Member
            • Dec 2007
            • 65

            #6
            Instead of
            Code:
            document.getElementById('vlan_name').value = str.toUpperCase();

            use

            Code:
            document.getElementById(temp.id).value = str.toUpperCase();

            Comment

            • vikas251074
              New Member
              • Dec 2007
              • 198

              #7
              Thanks very much madam. It is great to get answer from u.

              Thanks and regards,
              Vikas

              Comment

              Working...