need some help to write a javascript function

A

adi

Hello guys.

This is Aditya. I have a jsp where i am displaying more than 10,000
records and finally i am adding the values of these records in the end
and displaying the total value as Total: .
My Task:
Now i want to write a javafunction which can shrink these 10,000
records into a word say (Add). When the user comes and selects or
clicks this Add then he can view all the 10,000 records and if he
doesnot click Add, then only the total should be displayed.

I have already wriiten the logic to display the total only. Now i am
struck with the javascript part .

It would be really great if anybody help me out with this problem.
Waiting for your replies.

Thanks in Advance.
Aditya Reddy
 
T

Thomas 'PointedEars' Lahn

adi said:
[...] I have a jsp where i am displaying more than 10,000
records and finally i am adding the values of these records in the
end and displaying the total value as Total: .
My Task:
Now i want to write a javafunction which can shrink these 10,000
records into a word say (Add). When the user comes and selects or
clicks this Add then he can view all the 10,000 records and if he
doesnot click Add, then only the total should be displayed.

I have already wriiten the logic to display the total only. Now i am
struck with the javascript part .

JSP are JavaServer Pages, not JavaScript Pages. Java, unless related to
LiveConnect/XPConnect, is off-topic here and on-topic in comp.lang.java.ALL
instead.

You really don't need J(ava)Script here. What exactly do you want to
accomplish with it? Which part of J(ava)Script programming have you
problems with?

Please read <http://www.jibbering.com/faq/#FAQ2_3>.


PointedEars
 
Y

yukabuk

I think what shes trying to explain is have a hidden div containing
results which then displays after the user clicks on the 'Add' link.

Aditya, try this...

<div id='results' style='display:none;'>
....
All your html results in a table
....
</div>

<button
onmouseup='document.getElementById("results").style.display="inline";'>Add</
button>

Graham
 
T

Thomas 'PointedEars' Lahn

yukabuk said:
I think what shes trying to explain

.... which you have not quoted at all, despite e.g. the FAQ recommending
otherwise ...
is have a hidden div containing results which then displays after the user
clicks on the 'Add' link.

Aditya, try this...

<div id='results' style='display:none;'>
...
All your html results in a table
...
</div>

<button
onmouseup='document.getElementById("results").style.display="inline";'>Add</
button>

There are several fundamental problems with this approach:

1. The `div' element is not displayed if CSS is supported, support is
enabled, and client-side script support is not present, is disabled,
or is insufficient.

2. The `button' element requires HTML 4.01, while a more compatible

<input type="button" value="Add"
onmouseup="document.getElementById('results').style.display='inline';">

would have sufficed here as the caption is only text.

3. The button will not work without client-side scripting. As it is not
written with client-side scripting, when support is insufficient users
encounter a control that is apparently not working. A Bad Thing.

4. If client-side scripting is enabled, the button will also be activated
if one clicks elsewhere and only releases the mouse button over the
button because that is the definition of the `mouseup' event.

The button cannot be activated with the keyboard, only with a pointing
device. By not fulfilling this very basic criterion, the application
fails to meet standardized accessibility guidelines which are not only
desirable to meet but are often are required-by-law to meet in order
for the application to be even considered for public use or use within
a particular organization.

`onclick' is the proper event handler attribute to use here, not
`onmouseup'.

5. The button will not only not work but throw an exception if for some
reason sufficient DOM Level 1+ support is not available, as this support
is required by document.getElementById() and the method has been called
without prior feature test. This is the case e.g. in MSHTML 5.0, used
e.g. by Internet Explorer 5.0.

It will also error out if the method for some reason does not return an
object reference, as the return value is used untested in a reference
worm[tm]. The same goes for any other reference along the worm's path.

6. The `div' element is a block element, not an inline element; the
default value for its CSS `display' property is `block', not `inline'.

7. You are showing an infection with DIVitis: An additional `div' element
that the table is contained in is completely unnecessary; the table
itself can be hidden (but should only be hidden onload, with the
same scripting that later shows it):

<body onload="hideTable()">

8. Hiding the table does not prevent the whole table from being downloaded
and parsed although not needed/wanted, which can take quite long and is
probably not what the OP wants. ISTM they rather want the Add button to
display the entries that can be used to populate another table, for
which, as I said before, no client-side scripting is needed at all.

Considering these facts, I suggest you refrain from suggesting anything
further in this newsgroup, and to go back to the drawing board, if not your
student's books instead.


PointedEars
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top