Javascript Function with more then 2 dots
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Javascript Function with more then 2 dots

  1. #1
    Join Date
    Mar 2006
    Posts
    228

    Javascript Function with more then 2 dots

    Hello,

    I have the following code:

    Code:
    <html>
    <head>
    <script type="text/javascript">
    function product(ip,value1,value2)
    {
    alert(ip + "ghb"+ value1 + value2);
    }
    </script>
    </head>
    
    <body>
    <script type="text/javascript">
    document.write(product(192.168.0.15,60,20));
    </script>
    
    </body>
    </html>
    however it doesn't display the message like it's meant to.

    If i replace

    Code:
    document.write(product(192.168.0.15,60,20));
    with

    Code:
    document.write(product(192.168015,60,20));
    it works. As there is only 1 dot in the parameter for the IP Address. Soon as i put an extra dot it doesn't work.

    Does anyone have any ideas how to fix this or know what I am doing wrong.

    Thanks.

  2. #2
    Join Date
    Jan 2009
    Posts
    596

    Re: Javascript Function with more then 2 dots

    Javascript does not recognise the ip address in this code as valid syntax:
    Code:
    document.write(product(192.168.0.15,60,20));
    so it is encountering an error and not proceeding.

    In this code:
    Code:
    document.write(product(192.168015,60,20));
    The ip address is being recognised as a number, which is valid but produces the wrong result.

    To get the correct behaviour you will need to treat the ip address as a string:
    Code:
    document.write(product("192.168.0.15",60,20));

  3. #3
    Join Date
    Mar 2006
    Posts
    228

    Re: Javascript Function with more then 2 dots

    Hello,

    Thanks heaps.

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center