473,666 Members | 2,096 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

using a minus in javascript

I have the following link to bring up an alert with a figure in it based on
the screen resolution. but instead of displaying a number 'NaN' is
displayed.

<a href="javascrip t:alert('Your ideal estimated height is '+
screen.height*0 .55-screen.height*0 .2);" class="BodyLink ">Click to calculate
height </a>

But when I remove the part of the equation '-screen.height*0 .2' a figure is
displayed properly. Why doesnt it work when I have a minus in the equation.
Im not experienced with javascript so excuse if this is a basic question

thanks
ian

Dec 3 '06 #1
19 8396
any good links to doing calculations with javascript would also be very much
appreciated
"mantrid" <ia********@vir gin.netwrote in message
news:Wa******** *********@newsf e2-gui.ntli.net...
I have the following link to bring up an alert with a figure in it based
on
the screen resolution. but instead of displaying a number 'NaN' is
displayed.

<a href="javascrip t:alert('Your ideal estimated height is '+
screen.height*0 .55-screen.height*0 .2);" class="BodyLink ">Click to
calculate
height </a>

But when I remove the part of the equation '-screen.height*0 .2' a figure
is
displayed properly. Why doesnt it work when I have a minus in the
equation.
Im not experienced with javascript so excuse if this is a basic question

thanks
ian

Dec 3 '06 #2
Lee
mantrid said:
>
I have the following link to bring up an alert with a figure in it based on
the screen resolution. but instead of displaying a number 'NaN' is
displayed.

<a href="javascrip t:alert('Your ideal estimated height is '+
screen.height* 0.55-screen.height*0 .2);" class="BodyLink ">Click to calculate
height </a>

But when I remove the part of the equation '-screen.height*0 .2' a figure is
displayed properly. Why doesnt it work when I have a minus in the equation.
Im not experienced with javascript so excuse if this is a basic question
You're actually having trouble with the "+" operator, not the "-".
Your code:
1. calculates screen.height*0 .55
2. concatenates that value with "Your idea estimated height is ".
3. calculates screen.height*0 .2
4. tries to subtract that value from the string result of step 2
which is Not a Number.

Enclose your subtraction in parentheses, so it will be performed
before the concatenation:

'Your ideal estimated height is '+(screen.heigh t*0.55-screen.height*0 .2)

You really shouldn't be abusing he side-effect of the javascript:
pseudo-protocol that way, but if you must, you should have the
event handler return false to prevent the page from reloading
each time the link is clicked:

href="javascrip t:alert('Your ideal estimated height is '+
(screen.height* 0.55-screen.height*0 .2));return false"
--

Dec 3 '06 #3
Your statement is being confused by something called operator
presidence. Try wrapping the math part of the equation in an extra set
of parens like this:

alert('Your ideal estimated height is ' + (screen.height * 0.55 -
screen.height * 0.2))
It forces the equation to evaluate a number before trying to convert it
to a string and attach it to your message. As you had it written, the
equation was doing the multiplication operators first, then adding the
"Your ideal...." string to the first number, making it a string. When
it tried to subtract the second number, the parser thought "I can't
subtract a number from a string" and threw NaN at you instead.

Cheers!

</bd>
mantrid wrote:
any good links to doing calculations with javascript would also be very much
appreciated
"mantrid" <ia********@vir gin.netwrote in message
news:Wa******** *********@newsf e2-gui.ntli.net...
I have the following link to bring up an alert with a figure in it based
on
the screen resolution. but instead of displaying a number 'NaN' is
displayed.

<a href="javascrip t:alert('Your ideal estimated height is '+
screen.height*0 .55-screen.height*0 .2);" class="BodyLink ">Click to
calculate
height </a>

But when I remove the part of the equation '-screen.height*0 .2' a figure
is
displayed properly. Why doesnt it work when I have a minus in the
equation.
Im not experienced with javascript so excuse if this is a basic question

thanks
ian

Dec 3 '06 #4
Thanks
You really shouldn't be abusing he side-effect of the javascript:
pseudo-protocol that way, but if you must, you should have the
event handler return false to prevent the page from reloading
each time the link is clicked:
excuse my ignorance but can you clarify this. why is it abuse?
Dec 3 '06 #5
thanks
that worked

"manxomfoe" <br**********@g mail.comwrote in message
news:11******** **************@ j72g2000cwa.goo glegroups.com.. .
Your statement is being confused by something called operator
presidence. Try wrapping the math part of the equation in an extra set
of parens like this:

alert('Your ideal estimated height is ' + (screen.height * 0.55 -
screen.height * 0.2))
It forces the equation to evaluate a number before trying to convert it
to a string and attach it to your message. As you had it written, the
equation was doing the multiplication operators first, then adding the
"Your ideal...." string to the first number, making it a string. When
it tried to subtract the second number, the parser thought "I can't
subtract a number from a string" and threw NaN at you instead.

Cheers!

</bd>
mantrid wrote:
any good links to doing calculations with javascript would also be very
much
appreciated
"mantrid" <ia********@vir gin.netwrote in message
news:Wa******** *********@newsf e2-gui.ntli.net...
I have the following link to bring up an alert with a figure in it
based
on
the screen resolution. but instead of displaying a number 'NaN' is
displayed.
>
<a href="javascrip t:alert('Your ideal estimated height is '+
screen.height*0 .55-screen.height*0 .2);" class="BodyLink ">Click to
calculate
height </a>
>
But when I remove the part of the equation '-screen.height*0 .2' a
figure
is
displayed properly. Why doesnt it work when I have a minus in the
equation.
Im not experienced with javascript so excuse if this is a basic
question
>
thanks
ian
>
>
>

Dec 3 '06 #6
mantrid wrote:
any good links to doing calculations with javascript would also be very much
appreciated
"mantrid" <ia********@vir gin.netwrote in message
news:Wa******** *********@newsf e2-gui.ntli.net...
>>I have the following link to bring up an alert with a figure in it based

on
>>the screen resolution. but instead of displaying a number 'NaN' is
displayed.

<a href="javascrip t:alert('Your ideal estimated height is '+
screen.height *0.55-screen.height*0 .2);" class="BodyLink ">Click to

calculate
>>height </a>
Why not:
alert('Your ideal estimated height is '+screen.height *0.53)
?
screen.height*0 .55-screen.height*0 .2==screen.heig ht*0.53, no?
Mick

>>
But when I remove the part of the equation '-screen.height*0 .2' a figure

is
>>displayed properly. Why doesnt it work when I have a minus in the

equation.
>>Im not experienced with javascript so excuse if this is a basic question

thanks
ian


Dec 3 '06 #7
Lee
mantrid said:
>
Thanks
>You really shouldn't be abusing he side-effect of the javascript:
pseudo-protocol that way, but if you must, you should have the
event handler return false to prevent the page from reloading
each time the link is clicked:

excuse my ignorance but can you clarify this. why is it abuse?
First I need to point out that my advice to add "return false"
was incorrect. I was thinking of something else when I wrote
that. I'm getting old.

The intention of the javascript: pseudo-protocol is that the
Javascript expression will be evaluated and the resulting HTML
will replace the current contents of the page. What you're
doing is exploiting the side-effect. Your code doesn't return
any HTML, so the current contents are not replaced.

It's abuse because the browser is still expecting to load the
returned contents as a new page. This means that if you make
a little mistake that causes a value to be returned, you're
going to be back here asking why clicking this link replaces
your page with one that contains nothing but the string
"[Object]", or "[Window]", etc, and because certain other
operations cause unpredictable results in some browsers when
the browser thinks that it's about to load new content.
it's about to
--

Dec 3 '06 #8
manxomfoe wrote on 03 dec 2006 in comp.lang.javas cript:
Your statement is being confused by something called operator
presidence.
Indeed, but it should be "operator precedence".
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Dec 3 '06 #9
manxomfoe wrote:
>Your statement is being confused by something called operator
presidence.
It's "precedence ".

--
Bart.
Dec 3 '06 #10

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

Similar topics

2
13839
by: Newbie | last post by:
Hi, Could someone please tell how MINUS operator works for comparing and giving non-matching records in Table1? Does MINUS operator compares all records of Table1 with all records of Table2 to give differences? Say, i've got 2 tables - no keys defined on them. No PK and UK. Now MINUS operator will pick which columns for comparison? Having a PK/UK, i see it as comparing these keys and susequently the rest of fields for matcing key records,...
7
2987
by: johkar | last post by:
I am confused on childNodes or children. When you have nested lists, I would think it would all be one list in the Dom, this doesn't seem to be the case. So how do you traverse an unordered list? Any help appreciated. John In the below script, I can expand and contract the nodes when clicked on, but I want the menu to close all other siblings to the node clicked so that only one sub menu option is expanded at one time. If the node...
1
14024
by: Rob | last post by:
I have a date text box (input type = text) in an ASP.NET/Javascript environment. I wanted to force the users to enter dates in a "__/__/____", "dd/mm/yyyy" or similar format. The textbox needs to support normal copy/paste/delete format. There wasn't much on Google to help so (after a bit of toil) though I'd post my suggested solution here. No guarantees I'm afraid; just hope it helps somebody out there. Rob Here's the ASP source code:
5
2247
by: Jumbo | last post by:
I need a script for my site that shows my servertime minus 7 hours. Anyone who can help?
61
4919
by: Christoph Zwerschke | last post by:
On the page http://wiki.python.org/moin/Python3%2e0Suggestions I noticed an interesting suggestion: "These operators ≤ ≥ ≠ should be added to the language having the following meaning: <= >= != this should improve readibility (and make language more accessible to beginners).
16
2030
by: Giggle Girl | last post by:
Hi there, I have a nav tree similar to the XP Windows Explorer in behavior. It uses styles to underline a row on mouseover, and change the look of a row when clicked. Currently, it is working fine using CSS/Javascript, by calling functions that underline and highlight by passing in IDs. The problem is, I do not want to pass in IDs. Currently it has one the TDs to be changed, but I may need to add one for images (to change the
4
11545
by: tamnguyet | last post by:
I have n days and a date, I want a date plus(or minus) to n days.How can I do that in javascript
2
2283
by: Bluesangig | last post by:
Hi all, I am trying to append a TABLE element (being created dynamically) to an existing DIV element in a HTML document. But when trying to do so it is giving me the following error: Line: 141 Char: 5 Error: Unexpected call to method or property access. Code: 0 URL: http://localhost:8080/TreeViewer/tree_dyna_data.jsp
0
1267
by: thomas.mertes | last post by:
Generally C is well suited as target language for compilers. I use C as target language for the Seed7 compiler. This works good. There are just some things where the behaviour of C is undefined: The right shift operator (>>) of C may or may not sign extend for signed negative numbers. Since the right shift operation of Seed7 is defined as sign extending shift, I have to check if the C compiler does
0
8448
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8871
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8640
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6198
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4369
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2773
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1776
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.