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

Thread: Loop function

  1. #1
    New to the CF scene
    Join Date
    Oct 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Loop function

    in this point, the code works fine
    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>Untitled Document</title>
    </head>
    <body>
    <form name="zz">
    <input type="text" name="xx">
    <input type="text" readonly name="sasiakv">
    <input type="text" readonly name="sasiakm">
    <input type="button" onClick="dox();" value="Llogarit">
    </form>

    <script type="text/javascript">
    function dox()
    {
    kv=24;
    km=67;

    if(document.zz.xx.value>km){
    document.zz.xx.value=Number(document.zz.xx.value)-km;
    document.zz.sasiakm.value=Number(document.zz.sasiakm.value)+1}

    else if(
    document.zz.xx.value>2*kv){
    document.zz.xx.value=Number(document.zz.xx.value)-km;
    document.zz.sasiakm.value=Number(document.zz.sasiakm.value)+1}

    else{
    document.zz.xx.value=Number(document.zz.xx.value)-kv;
    document.zz.sasiakv.value=Number(document.zz.sasiakv.value)+1}
    }

    </script>
    </body>
    </html>
    but when i insert loop function script not work

    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>Untitled Document</title>
    </head>
    <body>
    <form name="zz">
    <input type="text" name="xx">
    <input type="text" readonly name="sasiakv">
    <input type="text" readonly name="sasiakm">
    <input type="button" onClick="dox();" value="Llogarit">
    </form>

    <script type="text/javascript">
    function dox()
    {
    kv=24;
    km=67;

    while (document.zz.xx.value<=0)
    {

    if(document.zz.xx.value>km){
    document.zz.xx.value=Number(document.zz.xx.value)-km;
    document.zz.sasiakm.value=Number(document.zz.sasiakm.value)+1}

    else if(
    document.zz.xx.value>2*kv){
    document.zz.xx.value=Number(document.zz.xx.value)-km;
    document.zz.sasiakm.value=Number(document.zz.sasiakm.value)+1}

    else{
    document.zz.xx.value=Number(document.zz.xx.value)-kv;
    document.zz.sasiakv.value=Number(document.zz.sasiakv.value)+1}
    }
    }
    </script>
    </body>
    </html>

  • #2
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,076
    Thanks
    38
    Thanked 498 Times in 492 Posts
    As far as I can see,
    Code:
    while (document.zz.xx.value<=0)
    {
    the '.value' has not been initialized to anything.
    Unknown if it is <= or > 0 to make any further changes to the value.

    In any case, always assume the worst case scenario which results in the program not working as expected.

  • #3
    New to the CF scene
    Join Date
    Oct 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks jmrker

    Code:
    Unknown if it is <= or > 0 to make any further changes to the value.
    this help me

  • #4
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,076
    Thanks
    38
    Thanked 498 Times in 492 Posts

    Thumbs up

    Quote Originally Posted by hckpro View Post
    thanks jmrker

    Code:
    Unknown if it is <= or > 0 to make any further changes to the value.
    this help me
    You're most welcome.
    Happy to help.
    Good Luck!


  •  

    Tags for this Thread

    Posting Permissions

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