www.webdeveloper.com
Results 1 to 5 of 5

Thread: correct parseflow syntax?

  1. #1
    Join Date
    Feb 2011
    Posts
    3

    Question correct parseflow syntax?

    Hi

    Im just writing a simple dynamic counter.

    Form:
    <form name="eqform">
    <input name="ButtonLectureplus" value="+1" type="button" onclick="lectureplus(0.75)">
    <input name="TextLecture" type="text" size="30" maxlength="30" readonly>
    </form>

    1). Function:
    function lectureplus(number)
    {document.eqform.TextLecture.value++;}

    This works in a way that "number" isnt used and 1 is added repeatedly.

    2). Function:
    function lectureplus(number)
    {document.eqform.TextLecture.value = document.eqform.TextLecture.value + number;}

    This doesnt work because he shows me "0,750,750,75 .... " (and also "+=0.75" shows the same result)

    alert (typeof document.eqform.TextLecture.value + number); show me "string0.75"

    I tried to use parsefloat() to force "document.eqform.TextLecture.value" be a number but can not find the right syntax to make it work.

    "parsefloat(document.eqform.TextLecture.value)" doesnt work

    Does someone know the right syntax?

    Thank Underlord

  2. #2
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    parseFloat(value, 10). Or you may use Number(value)

  3. #3
    Join Date
    Feb 2011
    Posts
    3
    Quote Originally Posted by Kor View Post
    parseFloat(value, 10). Or you may use Number(value)
    Works partly thanks

    alert (typeof parseFloat(document.eqform.TextLecture.value) shows number

    alert (parseFloat(document.eqform.TextLecture.value) + (parseFloat(number)));
    shows NaN0.75

    consequently
    parseFloat(document.eqform.TextLecture.value) = parseFloat(document.eqform.TextLecture.value) + (parseFloat(number));
    doesnt work either - any ideas for that?

    Im now trying to make an if statement because the first time I use the function parseFloat(document.eqform.TextLecture.value) = NULL and not 0.
    Well see how that goes.

  4. #4
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Use Number() instead of parseFloat(). It will return 0 if the value is an empty string. Parsing methods are, in fact, methods to parse a number from another base to decimal.

  5. #5
    Join Date
    Feb 2011
    Posts
    3
    Quote Originally Posted by Kor View Post
    Use Number() instead of parseFloat(). It will return 0 if the value is an empty string. Parsing methods are, in fact, methods to parse a number from another base to decimal.
    Yes that did it. Thanks a lot!!!

    document.eqform.TextLecture.value = Number(document.eqform.TextLecture.value) + Number(number);

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles