Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Nov 2002
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    is there a getdatatype function in javascript?

    i need to retrieve a datatype - is there a javascript function that will do so? i need it make sure that inputs in a form are all of data type number or integer...

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You can use the typeof keyword, but this only works with JS variables. Any value you retreive from a form input will be typeof 'string', unless you enact parseInt() on that string value, but then you'd already know that it is typeof 'number', so reading it's type with typeof would be a moot point.

    Are you trying to validate user input? Make sure they only enter numbers before submitting?

    P.S. The javascript variable types I can think of off the top of my head...

    number
    string
    boolean
    array
    object
    My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
    “Minds are like parachutes. They don't work unless they are open”
    “Maturity is simply knowing when to not be immature”

  • #3
    New to the CF scene
    Join Date
    Nov 2002
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    OK I see your point, thanks for the reply. I am trying to validate user input on a form and yes, I need all form variables to be in numerical format.

    Can you suggest a way to accomplish this?

    Thanks again...

  • #4
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by loadimmediate
    Can you suggest a way to accomplish this?
    Why I most certainly can! Click on the fValidate link in my signature!
    My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
    “Minds are like parachutes. They don't work unless they are open”
    “Maturity is simply knowing when to not be immature”


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •