•
•
•
•
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 361,626 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,226 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: 1200 | Replies: 4
![]() |
| |
•
•
Join Date: Oct 2007
Location: Penang Island, Malaysia
Posts: 160
Reputation:
Rep Power: 1
Solved Threads: 2
html Syntax (Toggle Plain Text)
<html> <head> <script type="text/javascript"> function validateFloat() { var o = document.frmInput.txtInput; switch (isFloat(o.value)) { case true: alert(o.value + " is an float") break; case false: alert(o.value + " is not an float") } } </script> </head> <body> <form name="frmInput"> Enter something: <input name="txtInput" size="4"> <input type="button" value="Validate" onclick="validateFloat()"></input> </form> </body> </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!"
•
•
Join Date: Mar 2008
Posts: 153
Reputation:
Rep Power: 1
Solved Threads: 19
The isFloat function is missing.
Matti Ressler
Suomedia
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
Suomedia - Dynamic Content Management
•
•
Join Date: Oct 2007
Location: Penang Island, Malaysia
Posts: 160
Reputation:
Rep Power: 1
Solved Threads: 2
•
•
Join Date: Mar 2008
Posts: 153
Reputation:
Rep Power: 1
Solved Threads: 19
This is rather simple (eg, it will return a.b as a float):
Google is your friend to find a more comprehensive float checking function.
Matti Ressler
Suomedia
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
Suomedia - Dynamic Content Management
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."
"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."
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb JavaScript / DHTML / AJAX Marketplace
Similar Threads
- fstream Tutorial (C++)
- Help with 1.pointers and 2.error checking (C++)
- bank account (C++)
- Differences Between Java and C/C++ (C++)
- Need Help With Error Checking User Input (C)
- Need help displaying when user enters negative number? (C++)
- error checking help (C)
- Interpretation of an instructors C++ program... (C++)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: drop down list
- Next Thread: Onclick does not work in ie for multiple object



Hybrid Mode