What's Going On?

W

Wayne Wengert

I jave a javascript function (see below) where if I uncomment the "if
(isNaN(z)..." line, the function won't execute. I need to pass floating
point numbers to the "map.center...." call and I had also tried to use a
statement like "var xx = parseFloat(x);" and that also causes the function
not to execute?

I put in various alerts and I know that the values are valid.

What am I missing here?

Wayne


============= function ===============
<script type="text/javascript">
//<![CDATA[
var x=document.Form1.txtLat.value;
var y=document.Form1.txtLong.value;
var z =document.Form1.txtZIPToFind.value;
alert("txtLat Value is: " + document.Form1.txtLat.value);
alert("Zip length is: " + z.length);
if(z.length ==5){
if (GBrowserIsCompatible()) {
alert("In mapping function");
var map = new GMap(document.getElementById("map"));
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());

//if (isNaN(z)) { alert('Please enter a valid 5 digit ZIP code!');
return; }

//map.centerAndZoom(new GPoint(x,y, 5);
}
}
//]]>
</script>
 
R

RobG

Wayne said:
I jave a javascript function (see below) where if I uncomment the "if
(isNaN(z)..." line, the function won't execute. I need to pass floating

Do you mean absolutely nothing happens? What does the script console say?

You only test the length of z, if you want a 5 digit number then you are
best to test it immediately after getting it and ask for it to be fixed:

var z = document.Form1.txtZIPToFind.value;
if ( ! /^\d{5}$/.test(z) ) {
// z isn't 5 digits exactly, deal with it
}
// continue processing as z is 5 digits

point numbers to the "map.center...." call and I had also tried to use a
statement like "var xx = parseFloat(x);" and that also causes the function
not to execute?

Validating numbers is tricky if you don't specify exactly what is
'valid' and what isn't. "-27" is a valid latitude in most systems, it
doesn't need to be a floating point number.

There are some hints on validating numbers here:

I put in various alerts and I know that the values are valid.

What am I missing here?

Try the above, post more information if it doesn't work.


[...]
 
W

Wayne Wengert

Rob;

Thanks for the response and suggestions. I will give those a try.

Wayne

RobG said:
Wayne said:
I jave a javascript function (see below) where if I uncomment the "if
(isNaN(z)..." line, the function won't execute. I need to pass floating

Do you mean absolutely nothing happens? What does the script console say?

You only test the length of z, if you want a 5 digit number then you are
best to test it immediately after getting it and ask for it to be fixed:

var z = document.Form1.txtZIPToFind.value;
if ( ! /^\d{5}$/.test(z) ) {
// z isn't 5 digits exactly, deal with it
}
// continue processing as z is 5 digits

point numbers to the "map.center...." call and I had also tried to use a
statement like "var xx = parseFloat(x);" and that also causes the
function not to execute?

Validating numbers is tricky if you don't specify exactly what is 'valid'
and what isn't. "-27" is a valid latitude in most systems, it doesn't
need to be a floating point number.

There are some hints on validating numbers here:

I put in various alerts and I know that the values are valid.

What am I missing here?

Try the above, post more information if it doesn't work.


[...]
 
A

ASM

Wayne said:
I jave a javascript function (see below) where if I uncomment the "if
(isNaN(z)..." line, the function won't execute. I need to pass floating
point numbers to the "map.center...." call and I had also tried to use a
statement like "var xx = parseFloat(x);" and that also causes the function
not to execute?

I put in various alerts and I know that the values are valid.

form values are allways strings (not numbers)
What am I missing here?

otherwise,
if z is nothing, z.length would give an error, so function breaks

var zL = (z && !!z.length)? z.length : 'no length (z unexisting)';
alert('Zip length is: ' + zL)
<script type="text/javascript">
//<![CDATA[
var x=document.Form1.txtLat.value;
var y=document.Form1.txtLong.value;
var z =document.Form1.txtZIPToFind.value;
alert("txtLat Value is: " + document.Form1.txtLat.value);
alert("Zip length is: " + z.length);
if(z.length ==5){
if (GBrowserIsCompatible()) {
alert("In mapping function");
var map = new GMap(document.getElementById("map"));
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());

//if (isNaN(z)) { alert('Please enter a valid 5 digit ZIP code!');
return; }

//map.centerAndZoom(new GPoint(x,y, 5);
}
}
//]]>
</script>
 
W

Wayne Wengert

Thanks for that information.

Wayne

ASM said:
Wayne said:
I jave a javascript function (see below) where if I uncomment the "if
(isNaN(z)..." line, the function won't execute. I need to pass floating
point numbers to the "map.center...." call and I had also tried to use a
statement like "var xx = parseFloat(x);" and that also causes the
function not to execute?

I put in various alerts and I know that the values are valid.

form values are allways strings (not numbers)
What am I missing here?

otherwise,
if z is nothing, z.length would give an error, so function breaks

var zL = (z && !!z.length)? z.length : 'no length (z unexisting)';
alert('Zip length is: ' + zL)
<script type="text/javascript">
//<![CDATA[
var x=document.Form1.txtLat.value;
var y=document.Form1.txtLong.value;
var z =document.Form1.txtZIPToFind.value;
alert("txtLat Value is: " + document.Form1.txtLat.value);
alert("Zip length is: " + z.length);
if(z.length ==5){
if (GBrowserIsCompatible()) {
alert("In mapping function");
var map = new GMap(document.getElementById("map"));
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());

//if (isNaN(z)) { alert('Please enter a valid 5 digit ZIP code!');
return; }

//map.centerAndZoom(new GPoint(x,y, 5);
}
}
//]]>
</script>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,072
Latest member
trafficcone

Latest Threads

Top