I got 2 inputs in a form where I want check if start > end. Seems like it
just compare the first number when I got this code in javascript
"if(document.al l.start > document.all.en d)"
How do i solve this so it compare 2 > 10 as, is two bigger than ten, and
not, is two bigger than one.
Thanx in advance 17 1562
In article <41********@new s.broadpark.no> , ka*****@hotmail .com enlightened us
with... I got 2 inputs in a form where I want check if start > end. Seems like it just compare the first number when I got this code in javascript "if(document.al l.start > document.all.en d)" How do i solve this so it compare 2 > 10 as, is two bigger than ten, and not, is two bigger than one. Thanx in advance
It's comparing them as strings, which is what the value always is. 2 > 1.
Use parseInt.
And get away from IE proprietary document.all syntax, which is AFAIU even
deprecated in IE6.
if (parseInt(docum ent.forms["formname"].elements["start"].value,10) >
parseInt(docume nt.forms["formname"].elements["end"].value,10) >
Note that this will fail if the value is not a number (null, blank, mix, etc)
- you should add a check for that in production code. Look at the isNaN
function and comparing to NaN.
--
--
~kaeli~
Acupuncture is a jab well done. http://www.ipwebdesign.net/wildAtHeart http://www.ipwebdesign.net/kaelisSpace
KS wrote: I got 2 inputs in a form where I want check if start > end. Seems like it just compare the first number when I got this code in javascript "if(document.al l.start > document.all.en d)" How do i solve this so it compare 2 > 10 as, is two bigger than ten, and not, is two bigger than one. Thanx in advance
<url: http://jibbering.com/faq/#FAQ4_21 />
You probably want: "if (+a > +b)" rather than "if (a > b)". See the URL above
for more information.
--
Grant Wagner <gw*****@agrico reunited.com>
comp.lang.javas cript FAQ - http://jibbering.com/faq
kaeli wrote: And get away from IE proprietary document.all syntax, which is AFAIU even deprecated in IE6.
I'd re-word that as "experience d JavaScript authors in this newsgroup (and
hopefully elsewhere) recommend against using the document.all collection to
access any DOM element".
This is because unfortunately Microsoft's document does not show document.all as
being deprecated.
What's even more unfortunate it does not even show that document.all is _not
recommended_ and suggest authors use the available DOM1 methods
(getElementById (), getElementsByTa gName(), etc) instead.
And with Gecko-based browsers now _supporting_ document.all (in addition to Opera
which has for some time), it is unlikely we will see the end of document.all in
our lifetimes.
To paraphrase a favorite quote of mine: In 20 million years when the continental
drift creates an earth unrecognizable and even cockroaches can't stand it
anymore, you can be sure that there remain Web servers buried far beneath the
ocean with scripts containing "document.a ll" thanks to Microsoft, Opera and now
Mozilla (insert insult against the Mozilla decision-makers here).
--
Grant Wagner <gw*****@agrico reunited.com>
comp.lang.javas cript FAQ - http://jibbering.com/faq
kaeli wrote: Grant Wagner wrote: <url: http://jibbering.com/faq/#FAQ4_21 />
You probably want: "if (+a > +b)" rather than "if (a > b)". See the URL above for more information.
<snip> Is there any downside to using the plus sign? I always use parseInt, but then you have to put in code to make sure it doesn't get pukey with NaN. How does the plus sign react to non-numbers or alphanumerics?
<URL: http://jibbering.com/faq/faq_notes/type_convert.html >
There is at least one downside to every method of converting a string
into a number. Unary plus forces a type-conversion so it uses the type
conversion rules. It's oddities are: an empty string becomes numeric
zero, (positive) "0x..." formats are interpreted as Hex (but it never
interprets anything as Octal) and "123e45" style strings are interpreted
into numbers like javascript numeric literals. Alphabetical (and most
alphanumeric) strings become NaN, as do - undefined - and all objects.
null and boolean false become zero, true becomes one.
It has been proposed that string input from users that is expected to be
a number should be verified using regular expressions prior to any
type-conversion or use of parseInt/float. And once that has been done an
accepted string should be safely amenable to whichever method best
suites the context. Unary plus (type-converting in general) is
considerably faster than parseInt/Float.
Richard.
kaeli wrote: In article <41************ ***@agricoreuni ted.com>, gw*****@agricor eunited.com enlightened us with... <url: http://jibbering.com/faq/#FAQ4_21 />
You probably want: "if (+a > +b)" rather than "if (a > b)". See the URL above for more information.
Grant,
Is there any downside to using the plus sign? I always use parseInt, but then you have to put in code to make sure it doesn't get pukey with NaN. How does the plus sign react to non-numbers or alphanumerics?
It converts anything that can't be converted into NaN, which is never less than,
greater than, or equal to, another Number or even NaN itself.
var a = 1, b = 'a';
alert(+a > +b); // false
alert(+a < +b); // false
alert(+a == +b); // false
var a = 'a', b = 'b';
alert(+a > +b); // false
alert(+a < +b); // false
alert(+a == +b); // false
This is the same behavior as parseInt() on the client-side implementations I've
tested.
I prefer the unary operator because we work with a server-side implementation of
JavaScript where parseInt() on an unparsable String returns 0, not NaN (actually I
seem to recall reading documentation that stated that it returns 0 due to some
underlying HP-UX dependancy, on Solaris and Windows NT, the product behaves
correctly). This may not seem like a significant problem, but it can be when you
need to distinguish between an actual unparsable value (NaN) and a zero (0).
Number() would give me the same effect as the unary operator but with worse
performance.
Just to be consistent and generate less errors, I've started to use the unary
operator on the client as well.
And it's easy enough to turn NaN into 0 if required:
var i = 'a';
i = +i || 0;
--
Grant Wagner <gw*****@agrico reunited.com>
comp.lang.javas cript FAQ - http://jibbering.com/faq
In article <cf************ *******@news.de mon.co.uk>, Ri*****@litotes .demon.co.uk enlightened us with... It has been proposed that string input from users that is expected to be a number should be verified using regular expressions prior to any type-conversion or use of parseInt/float. And once that has been done an accepted string should be safely amenable to whichever method best suites the context. Unary plus (type-converting in general) is considerably faster than parseInt/Float.
Good to know. I already check format with reg exp before parseInt anyway.
I think I'll be using this in the future for my textbox stuff. Neat trick.
Thanks to you and Grant.
--
--
~kaeli~
All I ask is the chance to prove that money cannot make me
happy. http://www.ipwebdesign.net/wildAtHeart http://www.ipwebdesign.net/kaelisSpace
Grant Wagner wrote: kaeli wrote: And get away from IE proprietary document.all syntax, which is AFAIU even deprecated in IE6. I'd re-word that as "experience d JavaScript authors in this newsgroup (and hopefully elsewhere) recommend against using the document.all collection to access any DOM element".
Oh, so I am not an "experience d JavaScript author" IYHO, thank you.
Be very careful with generalization.
This is because unfortunately Microsoft's document does not show document.all as being deprecated.
And support for users with browsers who don't know anything else should be
dropped IYHO? Remember out NN4 discussion lately[1]? I did not recommend
against trying with document.layers although NN4 is clearly deprecated by
Netscape, just wanted to have it given the least possible priority.
PointedEars
___________
[1] BTW, you really want to refrain from using the HTML composer.
Grant Wagner wrote: kaeli wrote: And get away from IE proprietary document.all syntax, which is AFAIU even deprecated in IE6. I'd re-word that as "experience d JavaScript authors in this newsgroup (and hopefully elsewhere) recommend against using the document.all collection to access any DOM element".
Oh, so I am not an "experience d JavaScript author" IYHO, thank you.
Be very careful with generalization.
This is because unfortunately Microsoft's document does not show document.all as being deprecated.
And support for users with browsers who don't know anything else should be
dropped IYHO? Remember our NN4 discussion lately[1]? I did not recommend
against trying with document.layers although NN4 is clearly deprecated by
Netscape, just wanted to have it given the least possible priority.
PointedEars
___________
[1] BTW, you really want to refrain from using the HTML composer. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Josef Sachs |
last post by:
Is Andrew Kuchling's regex-to-re HOWTO available anywhere?
I've found the following (dead) links on various Web pages:
http://py-howto.sourceforge.net/regex-to-re/regex-to-re.html
http://starship.skyport.net/crew/amk/regex/regex-to-re.html
http://www.python.org/doc/howto/regex-to-re/
http://www.amk.ca/python/howto/regex-to-re/
Thanks in advance.
|
by: Sue |
last post by:
Hello! I am back with another question.
Remember I am a new JavaScript student and I am aware that this code
does not check for all the possibilities and that as a "NEW"
JavaScript student I am not expected to check for everything.
At any rate, the problem I am having with the following code is that
it does not clear the fields once I press the SEND button. So can
anyone here enlighten me as to what is causing the problem.
|
by: Wilhelm Pieper |
last post by:
Hello,
HowTo: catch name/value pairs from request.form?
My viewstate shows:
"__VIEWSTATE=..&111=5.."
I want to get this pairs of IDs/names and values .
But because the DropDownList ist dynamically created I don't know the
name/ID of the created list. I can parse the viewState string to get the
related name/value pairs, but I think there will be a more simple way
|
by: John |
last post by:
Hi all,
I did post this about 10 hours ago thinking I would have received an answer
now but it is quite urgent.
How do I add a COM object to a web form?
I notice there's a primary interop assembly for Office web components and
what I'm trying to do here is to create a PivotTable object (which is fine)
but then I want to add it to a web page (e.g.
|
by: rob c |
last post by:
This is a minor thing and only appears in IE (so far), but I'd like to know to
correct it (if possible).
Whenever I use a form on a webpage, Explorer always leaves a blank line
following the </form> tag but Mozilla doesn't. Is there a way to supress the
blank line?
Thanks
Rob
www.rcp.ca
| |
by: grabit |
last post by:
Hi Peoples
i have a search page with a form field "subject" on my results page i have a paging routine . the first page lists its 10 records no trouble but when i click the "next" link i get a error telling me "subject is not defined in form"
How can i overcome this please.
I will post the page down to the end of the paging routine coz its not very long anyway.
<cfquery name="searchResults" datasource="#dsn#">
SELECT threadID, posttype,...
|
by: =?Utf-8?B?QVRT?= |
last post by:
HOWTO Make CStr for JavaScript on ASP w/ Request.Form and QueryString
In ASP, Request.Form and Request.QueryString return objects that do not
support "toString", or any JavaScript string operation on parameters not
passed.
Example: Make a TST.asp and post to it as TST.asp?STATE=TEST
<%@ Language=JavaScript %>
<%
|
by: blackrunner |
last post by:
ERROR in my Query?!
ERROR:
Element GESCHLECHT is undefined in FORM.
i think everything ok. Maby somebody can help me here
Element GESCHLECHT is undefined in FORM.
The error occurred in \anmeldung2.cfm: line 404
|
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...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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...
| |
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 project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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...
|
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();...
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |