SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    Non-Member cornwallis's Avatar
    Join Date
    Sep 2013
    Location
    india,canada
    Posts
    17
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Question add to the uppercase command in forms

    hi friends, i have to add to the uppercase command in HTML forms. In HTML forms when we enter the name of the user it has to change in caps. Your answer will be appreciated.

    thank you

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,496
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Welcome to the SP forums. That sounds like a javascript question to me, so I've moved your question to that forum.

  3. #3
    SitePoint Evangelist silver trophybronze trophy
    Join Date
    Jul 2013
    Posts
    406
    Mentioned
    22 Post(s)
    Tagged
    0 Thread(s)
    Language decisions!

    With javascript you can use the toUpperCase() function:
    HTML Code:
    <p>Your name: <input id="name" type="text" onkeyup="capitalize()"></p>
    Code:
    <script type="text/javascript">
    function capitalize(){
       var name=document.getElementById('name').value;
       name=name.toUpperCase();
       document.getElementById('name').value=name;
    }
    </script>
    As long as the visitor has javascript enabled, the input of the form appears as uppercase on screen, and will be send to the form-handler page as "hard coded capitals".

    =======
    If you only need the capitals on screen, you can use css instead:
    Code:
    #name2 {
       text-transform: uppercase;
    }
    HTML Code:
    <p>Your name: <input id="name2" type="text"></p>
    =======
    If you want the capitals in your database, even if javascript is disabled, then you can use the php-function strtoupper() [in the receiving php-page]. - This can be combined with the css method for the form page.

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,812
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    It is simpler in situations like this to allow the person to enter the value in mixed case and convert to uppercase on the server after the form is sublitted. You need to do that anyway in case JavaScript is turned off.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  5. #5
    Non-Member cornwallis's Avatar
    Join Date
    Sep 2013
    Location
    india,canada
    Posts
    17
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    thanks for helping me


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •