...

View Full Version : onBlur toUpperCase();



eck35
12-18-2003, 04:29 PM
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

Choopernickel
12-18-2003, 04:41 PM
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.

eck35
12-18-2003, 04:46 PM
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

A1ien51
12-18-2003, 04:53 PM
I persoannly would do it like this:


onBlur="ChangeToUpper(this);"


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


My 2 cents
Eric

requestcode
12-18-2003, 05:01 PM
Wouldn't the onChange event be better for this?

Choopernickel
12-18-2003, 05:02 PM
Or just this:


<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:


...
<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.

eck35
12-18-2003, 05:03 PM
Thanks, exactly what I needed...

eck35



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum