×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

How can you change a textbox's format?

How can you change a textbox's format?

How can you change a textbox's format?

(OP)
Hello.  I'm new with web design, and Frontpage in general.

Is there a way I can format a textbox so that when the user enters something it comes up as decimal format.

Like when the page loads it could say "0.0" in the box.  Then the user clicks in it, and enters "18."  After he clicks enter, or clicks out of the box, the format on the textbox changes it to "1.8" or ".18"

Is there a way to do this?  Thanks for any help.

RE: How can you change a textbox's format?

Something like this but this isn't a foolproof version.  If the user enters 1.8 he will get 1..8

CODE

<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
<script language="vbscript">
sub numb_onChange
   dim val, vallen, lhs, rhs
   val = numb.value
   vallen = len(val)
   if vallen <> 0 then
      rhs = right(val,1)
      if vallen = 1 then
         lhs = ""
      else
         lhs = left (val, vallen - 1)
      end if
      numb.value = lhs & "." & rhs
   end if
end sub
</script>
</HEAD>
<BODY>

<P><INPUT type="text" name="numb"></P>
<INPUT type="text" name="dumb">
</BODY>
</HTML>

RE: How can you change a textbox's format?

(OP)
This is exactly what I needed thank you so much.

RE: How can you change a textbox's format?

(OP)
The only problem I see with it is that if the user goes back to enter more, it will insert another decimal place.  So 1.8 will become 1.8.6 if they insert another 6.

I tried to enter another condition to see if there is already a decimal before the last number.  However, this isn't working.  The code's below.  Got any ideas?

_______________________________________________
sub T5_onChange
   dim val, vallen, lhs, rhs
   val = T5.value
   vallen = len(val)
   if vallen <> 0 then
    if left(right(T5.value,2),1) <> "." then
      rhs = right(val,1)
      if vallen = 1 then
         lhs = 0
      else
         lhs = left (val, vallen - 1)
      end if
      
      T5.value = lhs & "." & rhs
    end if
   end if
end sub

RE: How can you change a textbox's format?

(OP)
Nevermind, I got it.  I changed it to:

sub T5_onChange
   dim val, vallen, lhs, rhs
   'dim saveNum
   val = T5.value
   vallen = len(val)
   if vallen <> 0 then
    if InStr(val , ".") = 0 then   '<-----Added condition
      rhs = right(val,1)
      if vallen = 1 then
         lhs = 0
      else
         lhs = left (val, vallen - 1)
      end if
      'if T5.value <>
      T5.value = lhs & "." & rhs
      'T5.value = left(right(T5.value,2),1)
      'saveNum = left(right(T5.value,2),1)
    end if
   end if
end sub

Thanks for the help.

RE: How can you change a textbox's format?

I did say it wasn't a foolproof version.  You have to test with all sorts of data.  Here are some.

CODE

1800
1800.
180.0
18.00
1.800
fred
fried.rice
18..0
18.,0
The ones with at least one dot will bypass your test but are they correct?  The real question is how idiot proof do you want it and how intelligent you think your users are.  Kindergarten kids doing data entry on a stock exchange system can completely wreck it but somehow stock exchange workers hardly ever seem to.

Maybe a sanity check at the end would be useful.  Something that takes cdbl of the value and does something with it to check that it is non zero.  Nothing is idiot proof but do you expect idiots to use it?

RE: How can you change a textbox's format?

(OP)
Yeah I know idiots are going to use it.  I put in more conditions since I pasted that, and tested it with everything I can imagine people putting in.

For my purposes, it's doing everything I want it to.  Thanks for all your help!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close