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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Oct 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Please help me| why not work

    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>Untitled Document</title>
    <script type="text/javascript">
    function dox()
    {
    kv=24;
    km=67;

    for (;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(do cument.zz.xx.value)-kv;document.zz.sasiakv.value=Number(document.zz.sasiakv.value)+1}

    }
    }
    </script>
    </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>

    </body>
    </html>

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,398
    Thanks
    12
    Thanked 570 Times in 563 Posts
    It's very difficult to follow your code, because you didn't read the forum rules so you didn't know how to properly use the editor symbol "#" for your code segment.

    Generally: If you compare the value of an input (which is always a string) to an integer, you should convert the string to integer BEFORE the comparison takes place. Otherwise you might get strange and unexpected results.

    On top of all that: You HAVE TO describe in your "question" what the goal of your code is. How the heck should we know? Working crystal balls are really really expensive, you know?

    Your code will ONLY do something, if you enter a negative number (or zero) in the field with name 'xx' in the first place and will then go into and endless loop. All positive values will have no effect.

    So what did you WANT to do?
    Last edited by devnull69; 10-23-2013 at 10:06 PM.

  • #3
    Regular Coder
    Join Date
    Aug 2012
    Posts
    122
    Thanks
    0
    Thanked 25 Times in 25 Posts
    hi hckpro,

    i fiddled with your coding and please keep in mind, this does not absolve what was said by devnull69, as i just fiddled with it and not quite sure what you're looking to do but this appears to make something work based on your code:

    Code:
    <!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>
    hope this helps
    1 Corinthians 15:3-4 / Ephesians 2:8-9 - What or Who are you living for?


  •  

    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
    •