473,405 Members | 2,338 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,405 software developers and data experts.

How would I use JS to get this value?

Hi,

On my HTML page, I have a number of SPANs like

<span class="myNumber">3</span>

What I would like is a way to return the maximum number in between the
SPANs. You can assume that if I have an HTML block like the above, I
will also have

<span class="prescriptionNumber">1</span>
<span class="prescriptionNumber">2</span>

somewhere on my page before it.

Thanks for your help, - Dave
Aug 3 '08 #1
5 1281
laredotornado wrote on 03 aug 2008 in comp.lang.javascript:
Hi,

On my HTML page, I have a number of SPANs like

<span class="myNumber">3</span>

What I would like is a way to return the maximum number in between the
SPANs. You can assume that if I have an HTML block like the above, I
will also have

<span class="prescriptionNumber">1</span>
<span class="prescriptionNumber">2</span>

"returning the maximum number in between the SPANs."

What is a "maximum number in between"?
somewhere on my page before it.
Before what it?

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Aug 3 '08 #2
laredotornado meinte:
Hi,

On my HTML page, I have a number of SPANs like

<span class="myNumber">3</span>

What I would like is a way to return the maximum number in between the
SPANs. You can assume that if I have an HTML block like the above, I
will also have

<span class="prescriptionNumber">1</span>
<span class="prescriptionNumber">2</span>

somewhere on my page before it.
(1) Get collection of all spans with className "prescription".
(2) Collect the first childNode of all those spans.
(3) convert the nodeValues of those childNodes to numbers (if needed).
(4) search highest value of those numbers.

Gregor


--
http://photo.gregorkofler.at ::: Landschafts- und Reisefotografie
http://web.gregorkofler.com ::: meine JS-Spielwiese
http://www.image2d.com ::: Bildagentur für den alpinen Raum
Aug 3 '08 #3
On Aug 3, 3:15*pm, Gregor Kofler <use...@gregorkofler.atwrote:
laredotornadomeinte:
Hi,
On my HTML page, I have a number of SPANs like
<span class="myNumber">3</span>
What I would like is a way to return the maximum number in between the
SPANs. *You can assume that if I have an HTML block like the above, I
will also have
<span class="prescriptionNumber">1</span>
<span class="prescriptionNumber">2</span>
somewhere on my page before it.

(1) Get collection of all spans with className "prescription".
(2) Collect the first childNode of all those spans.
(3) convert the nodeValues of those childNodes to numbers (if needed).
(4) search highest value of those numbers.

Gregor

--http://photo.gregorkofler.at::: Landschafts- und Reisefotografiehttp://web.gregorkofler.com*::: meine JS-Spielwiesehttp://www.image2d.com* ** ::: Bildagentur für den alpinen Raum
Thanks. How do I 'Get collection of all spans with className
"prescription"'? - Dave
Aug 4 '08 #4
laredotornado wrote:
On Aug 3, 3:15 pm, Gregor Kofler <use...@gregorkofler.atwrote:
>laredotornadomeinte:
>>On my HTML page, I have a number of SPANs like
<span class="myNumber">3</span>
What I would like is a way to return the maximum number in between the
SPANs. You can assume that if I have an HTML block like the above, I
will also have
<span class="prescriptionNumber">1</span>
<span class="prescriptionNumber">2</span>
somewhere on my page before it.
(1) Get collection of all spans with className "prescription".
(2) Collect the first childNode of all those spans.
(3) convert the nodeValues of those childNodes to numbers (if needed).
(4) search highest value of those numbers.
[...]

Thanks. How do I 'Get collection of all spans with className
"prescription"'?
Google is your friend.
PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
Aug 4 '08 #5
laredotornado <la***********@zipmail.comwrites:
Thanks. How do I 'Get collection of all spans with className
"prescription"'?
There is no single method that does that, so you have to write a
function yourself.
In this case, since you are only looking for "span" elements,
you could use document.getElementsByTagName to get all span
elements in the document, and then run through that and operate
on those with a "className" property containing "prescription".

E.g.
function getPrescriptions() {
var ps = [];
var spans = document.body.getElementsByTagName("span");
for(var i = 0, n = spans.length; i < n; i++) {
var sp = spans[i];
if (/\bprescription\b/.test(sp.className)) {
ps.push(sp);
}
}
return ps;
}

Good luck
/L
--
Lasse Reichstein Nielsen
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Aug 4 '08 #6

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

Similar topics

1
by: G Kannan | last post by:
Hey all! I have written a perl script to retrieve information from a HTML Form and insert the data into an Oracle database table. I am gettting the the following error message: "Use of...
3
by: otto | last post by:
i need to read a variable in a javascript and translate it to a form in html the javascript variable is: <SCRIPT LANGUAGE='JavaScript'>RF2N('Total');</script> and i need to put that...
3
by: Eric Chang | last post by:
I was working on this simple form with radio boxes. And when I click on one of the radio box, it tell me the value is "undefined" Why is that ? I did defined the value of each radio box: ...
16
by: cwizard | last post by:
I'm calling on a function from within this form, and there are values set but every time it gets called I get slammed with a run time error... document.frmKitAmount.txtTotalKitValue is null or not...
4
by: dmiller23462 | last post by:
So here's my problem.....I need to set up different email distributions based on which option in the following Select form has been chosen....For instance if "Putaway" is chosen it needs to email...
7
by: matthew_carver | last post by:
Hello, I have an ASP page that loops through a SQL Server 2000 table, then downloads an Excel sheet the users can save, etc. Works fine, except, I see that in one particular "comments" field the...
13
by: dbuchanan | last post by:
Hello, Here is the error message; ---------------------------- Exception Message: ForeignKeyConstraint Lkp_tbl040Cmpt_lkp302SensorType requires the child key values (5) to exist in the...
0
by: tania | last post by:
i have this table in my database: CREATE TABLE FILM( F_ID INT(5) NOT NULL AUTO_INCREMENT, F_TITLE VARCHAR(40) NOT NULL, DIRECTOR_FNAME VARCHAR(20) NOT NULL, DIRECTOR_LNAME VARCHAR(20) NOT NULL,...
1
by: cbellew | last post by:
Hi guys, I have a problem with an option group and a two corresponding text boxes. When the user chooses an option value i want the text boxes to populate with text dependent on the choice made....
275
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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.