Case Conversion

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bytesbytes
    New Member
    • Apr 2008
    • 16

    Case Conversion

    How to convert the case on clicking a button dynamically?
    If a button is clicked first time then it should display the cahracters in CAPITAL in a text box and clicking the same button second time should display in text as small character and vice versa.
    Please provide me sample coding if you have.

    THANKS in advance
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Use the string's toUpperCase/toLowerCase methods.

    Comment

    • bytesbytes
      New Member
      • Apr 2008
      • 16

      #3
      Thanks for your reply. But the requirement is clicking a button should change the case in vise versa manner like Caps Lock in key board.(Required the same function)

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Show your code so far so I can suggest changes/additions.

        Comment

        • hsriat
          Recognized Expert Top Contributor
          • Jan 2008
          • 1653

          #5
          Originally posted by bytesbytes
          Thanks for your reply. But the requirement is clicking a button should change the case in vise versa manner like Caps Lock in key board.(Required the same function)
          You need to check the keyCode on the keypress event. If the keycode is on an alphabet, convert it to the required case's code (depending upon the status of the button).

          Comment

          • bytesbytes
            New Member
            • Apr 2008
            • 16

            #6
            Thanks. But how do i know how many times i pressed the capslock button.For first time pressing it should return all values in text as CAPITAL and second time being small and 3rd time being CAPITAL and so on. Can you please provide sample codings?
            [HTML]<input name="textarea" type="text" />
            <input type="button" name="button1" onclick="type(' a')" />
            <input type="button" name="button1" onclick="type(' b')" />
            <input type="button" name="Capsbutto n" ___? />
            [/HTML]****
            [CODE=javascript]function type(x){
            var object =document.getEl ementById("text area");
            var app = object.value;
            object.value=ap p+x;
            }
            [/CODE]
            Please provide for caps lock function.
            Last edited by acoder; Jul 2 '08, 02:28 PM. Reason: Added [code] tags

            Comment

            • hsriat
              Recognized Expert Top Contributor
              • Jan 2008
              • 1653

              #7
              Save a flag variable, which gets toggled onclick of the button.
              true = CAPITALS
              false = smalls

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                bytesbytes, you've been told before about using code tags. They make the code much easier to read. See How to Ask a Question. I don't want to have to ask you again.

                Moderator.

                Comment

                Working...