Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Aug 2003
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    onBlur toUpperCase();

    Greetings All.

    Many thanks in advance.

    I am trying to change text toUpperCase() after the textboxe loses focus. What I am doing incorrectly???

    function upper(fld)
    {
    var inputStr = fld.value
    var fldName = fld.name
    var formName = fld.form.name

    alert("document.forms(0)." + formName + "." + fldName + ".value.toUpperCase()");

    document.forms(0).fldName.inputStr.toUpperCase();
    }


    <input type="text" name="HOSPNAME" size="40" maxlength="30" onBlur="upper(this.form.HOSPNAME);"
    &VHOSPNAME.EVAL &RO.EVAl>

    <input type="text" name="HOSPADDR1" size="40" maxlength="30 onBlur="upper(this.form .HOSPADD1);
    &VHOSPADDR1.EVAL &RO.EVAL>


    Any direction or input would be greatly appreciated.

    Again, many thanks,

    onBlur:
    eck35

  • #2
    Regular Coder
    Join Date
    Apr 2003
    Location
    Atlanta, GA
    Posts
    487
    Thanks
    0
    Thanked 0 Times in 0 Posts
    What's this?

    &VHOSPADDR1.EVAL &RO.EVAL
    That shouldn't be inside your HTML tags, unless it's some piece of server-side code we don't know about.

  • #3
    New Coder
    Join Date
    Aug 2003
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yes, it is needed. the first amper variable is the value being read into the box. The second amper variable is to make the box read only when a condition is true.

    As to me question, if the user enters text I want to drive it toUpperCase();

    thx

    eck35

  • #4
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    I persoannly would do it like this:


    onBlur="ChangeToUpper(this);"


    function ChangeToUpper(theElement){
    theElement.value = theElement.value.toUpperCase();
    }


    My 2 cents
    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Posts
    626
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Wouldn't the onChange event be better for this?

  • #6
    Regular Coder
    Join Date
    Apr 2003
    Location
    Atlanta, GA
    Posts
    487
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Or just this:

    Code:
    <input type="text"... onblur="this.value.toUpperCase();" />
    Of course, I like to obfuscate these issues far past the point of handiness, all the way to completely non-intrusive DHTML. Watch:

    Code:
    ...
    <script type="text/javascript">
    window.onload=function() {
       var inputs = document.getElementsByTagName('input'),
          i = inputs.length;
       while (--i) {
          if (inputs[i].type == 'text' && 
                inputs[i].className.indexOf('allcaps') > -1) {
             inputs[i].onkeyup = toUpper;
          }
      }
    }
    function toUpper() {
       this.value.toUppercase();
       return true;
    }
    </script>
    </head>
    <body>
    <form ...>
    <input type="text" ... class="allcaps" />
    <input type="text" ... class="regulartext" />
    ...
    The first input there will be all capitals all the time. The second will be like normal text, until you programatically add the string "allcaps" to its className property.




    ...but that's just me.

  • #7
    New Coder
    Join Date
    Aug 2003
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks, exactly what I needed...

    eck35


  •  

    Posting Permissions

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