User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 375,235 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,016 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 1270 | Replies: 4
Reply
Join Date: Oct 2007
Location: Penang Island, Malaysia
Posts: 165
Reputation: lordx78 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
lordx78's Avatar
lordx78 lordx78 is offline Offline
Junior Poster

Help Float value checking

  #1  
Mar 23rd, 2008
  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. function validateFloat()
  5. {
  6. var o = document.frmInput.txtInput;
  7. switch (isFloat(o.value))
  8. {
  9. case true:
  10. alert(o.value + " is an float")
  11. break;
  12. case false:
  13. alert(o.value + " is not an float")
  14. }
  15. }
  16.  
  17. </script>
  18. </head>
  19. <body>
  20. <form name="frmInput">
  21. Enter something: <input name="txtInput" size="4">
  22. <input type="button" value="Validate" onclick="validateFloat()"></input>
  23. </form>
  24. </body>
  25. </html>

Not working. pls help
Last edited by lordx78 : Mar 23rd, 2008 at 6:12 am.
"I might not be the BEST but I'm not like the REST!"
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Mar 2008
Posts: 153
Reputation: Suomedia is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 19
Suomedia Suomedia is offline Offline
Junior Poster

Re: Float value checking

  #2  
Mar 23rd, 2008
The isFloat function is missing.


Matti Ressler
Suomedia
If you want your dreams to come true, the first thing you must do is to wake up....
Suomedia - Dynamic Content Management
Reply With Quote  
Join Date: Oct 2007
Location: Penang Island, Malaysia
Posts: 165
Reputation: lordx78 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
lordx78's Avatar
lordx78 lordx78 is offline Offline
Junior Poster

Re: Float value checking

  #3  
Mar 24th, 2008
can u help me to solve isFloat, pls.
"I might not be the BEST but I'm not like the REST!"
Reply With Quote  
Join Date: Mar 2008
Posts: 153
Reputation: Suomedia is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 19
Suomedia Suomedia is offline Offline
Junior Poster

Re: Float value checking

  #4  
Mar 24th, 2008
This is rather simple (eg, it will return a.b as a float):

function isFloat(value) {
            if (/\./.test(value)) {

                return true;

            } else {

                return false;

            }
          }


Google is your friend to find a more comprehensive float checking function.


Matti Ressler
Suomedia
Last edited by Suomedia : Mar 24th, 2008 at 12:16 pm.
If you want your dreams to come true, the first thing you must do is to wake up....
Suomedia - Dynamic Content Management
Reply With Quote  
Join Date: Jun 2006
Location: India
Posts: 6,732
Reputation: ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold 
Rep Power: 23
Solved Threads: 323
Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Rebellion Revamped

Re: Float value checking

  #5  
Mar 30th, 2008
A thorough way of doing it would be:
/**
 * Checks if a given string is float or not
 *
 * @author sos
 * @param {String} val The string in question.
 */
  function isFloat(val) {
    if(!val || (typeof val != "string" || val.constructor != String)) {
      return(false);
    }
    var isNumber = !isNaN(new Number(val));
    if(isNumber) {
      if(val.indexOf('.') != -1) {
        return(true);
      } else {
        return(false);
      }
    } else {
      return(false);
    }
  }
"I don't accept change. I don't deserve to live."

"Working a real job is a win if you're lazy, greedy, or unmotivated. If you're average, you fit right in. And if you're above average, the basic terms of employment and premise of the arrangement is against your interests."
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb JavaScript / DHTML / AJAX Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 4:18 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC