473,398 Members | 2,380 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

What's Going On?

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>
Aug 20 '05 #1
4 1284
Wayne Wengert wrote:
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:

<URL:http://www.merlyn.demon.co.uk/js-valid.htm#VNP>

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.
[...]

--
Rob
Aug 20 '05 #2
Rob;

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

Wayne

"RobG" <rg***@iinet.net.au> wrote in message
news:43***********************@per-qv1-newsreader-01.iinet.net.au...
Wayne Wengert wrote:
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:

<URL:http://www.merlyn.demon.co.uk/js-valid.htm#VNP>

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.
[...]

--
Rob

Aug 20 '05 #3
ASM
Wayne Wengert wrote:
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>

--
Stephane Moriaux et son [moins] vieux Mac
Aug 20 '05 #4
Thanks for that information.

Wayne

"ASM" <st*********************@wanadoo.fr.invalid> wrote in message
news:43**********************@news.wanadoo.fr...
Wayne Wengert wrote:
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>

--
Stephane Moriaux et son [moins] vieux Mac

Aug 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

125
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
13
by: Jason Huang | last post by:
Hi, Would someone explain the following coding more detail for me? What's the ( ) for? CurrentText = (TextBox)e.Item.Cells.Controls; Thanks. Jason
9
by: Jay | last post by:
Everywhere I go (read/browse) I see these parameters.... ByVal sender As Object, ByVal e As System.EventArgs Yet I never see them used within the function/method. Could someone tell me what they...
63
by: Jake Barnes | last post by:
In the course of my research I stumbled upon this article by Alex Russel and Tim Scarfe: http://www.developer-x.com/content/innerhtml/default.html The case is made that innerHTML should never...
7
by: newbie | last post by:
anyone know is it this source code value:- T = ((Y >> 4) ^ X) & 0x0F0F0F0F; X ^= T; Y ^= (T << 4); T = ((Y ) ^ X) & 0x10101010; X ^= T; Y ^= (T ); X = (LHs << 3) | (LHs << 2)...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
6
by: LurfysMa | last post by:
I am working on an electronic flashcard application. I have one version up and running using Visual Basic (6.0) and Access 2000. My long-range plans are to put it up on a website and sell...
98
by: tjb | last post by:
I often see code like this: /// <summary> /// Removes a node. /// </summary> /// <param name="node">The node to remove.</param> public void RemoveNode(Node node) { <...> }
10
by: JoeC | last post by:
I have been programming for a while and I have seen this syntax before and I copied this from a book but the book didn't explain what is going on here. class engine{ protected: static engine*...
6
by: BJ | last post by:
I just started this week on a new project. The existing project uses BEA Tuxedo as a second layer service broker. The clients make calls to the Tux services which in turn retrieves data from an...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.