Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / JScript / December 2004

Tip: Looking for answers? Try searching our database.

onFocus problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
masoud bayan - 29 Nov 2004 20:11 GMT
Hi,

I have a web page with 20 textboxes that user enters different amount in
them. I want to show these amounts in currency format ($123,456.12) in this
way that : as soon as user clicks on text box (or text box has focus) value
in that filed is changed from currency to numeric format and when this
control loose focus, value from numeric is changed to currency format (the
way MS Excel works).

<input name="txtAmount" type="text" value="$97,000.12" id="txtAmount"
OnBlur="convertToCurrency(this);" OnFocus="convertToNumeric(this);" />

function convertToNumeric(objFld)
{
   objFld.value=CurrencyToFloat(objFld.value);
}

function convertToCurrency(objFld)
{
   objFld.value=ToCurrency(objFld.value);
}

But as soon as control gets focus and function is called, onfocus is run in
an infinite loop.

I appreciate it if anybody can provide me with his advice.

Thanks
sshimla - 09 Dec 2004 13:56 GMT
Hi,

Well, I must say... I copied your code but only changed as following
(to save myself writing the conversion functions):

function convertToNumeric(objFld)
{
objFld.value="9700012";
}

function convertToCurrency(objFld)
{
objFld.value="$97,000.12";
}

And it didn't loop endlessly...
2 options:

1) Your conversion function is looping endlessly
2) In any case, you can always write a validation function like
ValidateIsNumeric and add a little IF statement in you
convertToNumeric function to appear like this:

function convertToNumeric(objFld)
{
  if (!ValidateIsNumeric(objFld.value))
  {
      objFld.value=CurrencyToFloat(objFld.value);
  }
}

This might also increase performance on your client browser slightly
if the conversion is a painfull one, just use regular expressions to
make sure there are only digits there...

The loop will still be there I guess but who knows... You can also
send me your actual conversion functions and I'll have a look, we
might also be able to manipulate it with the onkeypress event.

Best of luck!
masoud bayan - 15 Dec 2004 16:31 GMT
Hi,

Thanks for your reply.

Well, you are right it is working properly.
My mistake : I was testing application in debug mode so each time onfocus
was called and application stopped at breakpoint then when I hit run and
went back to application  onFocus function was called and it caused and
endless loop.

Thanks again for your follow up.
Masoud

> Hi,
>
[quoted text clipped - 41 lines]
>   www.GroupSrv.com
> *-----------------------*

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.