-
November 29th, 2011, 05:30 PM
#1
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.
-
November 29th, 2011, 06:37 PM
#2
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));
-
November 29th, 2011, 06:59 PM
#3
Re: Javascript Function with more then 2 dots
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|