Re: field value AFTER numeric validation

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • sylver

    Re: field value AFTER numeric validation

    The focus goes to the field again, and the field value now is 12q.
    But I want the field value turns 12. That is, without the last non-
    numeric key value pressed. Am I clear enough?
    To convert "12q" to "12":
    var text = "12q";
    var twelve = parseInt(text);
    //twelve == 12

    or you can user parseFloat()..d epends on your needs :D
  • Dr J R Stockton

    #2
    Re: field value AFTER numeric validation

    In comp.lang.javas cript message <64e16c6a-0a07-47a4-83fa-51cc57e70985@d1
    9g2000prm.googl egroups.com>, Mon, 2 Jun 2008 06:12:03, sylver
    <gamergemparq@g mail.composted:
    >
    >The focus goes to the field again, and the field value now is 12q.
    >But I want the field value turns 12. That is, without the last non-
    >numeric key value pressed. Am I clear enough?
    >
    >To convert "12q" to "12":
    >var text = "12q";
    >var twelve = parseInt(text);
    >//twelve == 12
    And what would you expect from "09q" ?

    It's a good idea to read the newsgroup c.l.j and its FAQ. See below.

    --
    (c) John Stockton, nr London UK. ?@merlyn.demon. co.uk IE7 FF2 Op9 Sf3
    news:comp.lang. javascript FAQ <URL:http://www.jibbering.c om/faq/index.html>.
    <URL:http://www.merlyn.demo n.co.uk/js-index.htmjscr maths, dates, sources.
    <URL:http://www.merlyn.demo n.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.

    Comment

    • Evertjan.

      #3
      Re: field value AFTER numeric validation

      Dr J R Stockton wrote on 02 jun 2008 in comp.lang.javas cript:
      In comp.lang.javas cript message <64e16c6a-0a07-47a4-83fa-51cc57e70985@d1
      9g2000prm.googl egroups.com>, Mon, 2 Jun 2008 06:12:03, sylver
      <gamergemparq@g mail.composted:
      >>
      >>The focus goes to the field again, and the field value now is 12q.
      >>But I want the field value turns 12. That is, without the last non-
      >>numeric key value pressed. Am I clear enough?
      >>
      >>To convert "12q" to "12":
      >>var text = "12q";
      >>var twelve = parseInt(text);
      >>//twelve == 12
      >
      And what would you expect from "09q" ?
      >
      It's a good idea to read the newsgroup c.l.j and its FAQ. See below.
      Indeed, but just as important is,
      that '12p' could easily have ment 120,
      and this would be accepted as 12 without informing the user.

      I think parseInt() should not be used for parsing user input.

      --
      Evertjan.
      The Netherlands.
      (Please change the x'es to dots in my emailaddress)

      Comment

      • fixertool

        #4
        Re: field value AFTER numeric validation

        Thanks for all the help. You all were very helpful.

        I forgot to say that I was working only for IE (it's an intranet,
        using sharepoint too)

        Dr.
        I put "12p" as an example. I'd expect you understand it's just that.
        What do you need? Something like xxxxz (x representing a number, z any
        other key)?
        Come on, doc.

        And what would you expect from "09q" ?

        Comment

        Working...