473,503 Members | 722 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

AJAX Page - looking for advice about next step please

32 New Member
I've read this article:
http://www.oracle.com/technology/pub...lman-ajax.html

And from reading it thought it'd be interesting to try a bit of Ajax on my site.

What I'd really like to do is to set up a little ajax widget on my site, so that if people want to view more of the ecard thumbnails, they can click little next/prev icons to view the next / previous 8 thumbnail ecard images. I suppose in a way I want it to be similar to the thumbnail widget used on flickr.com.

I've managed to get a simple bit of ajax running on this demo page:

http://jimpix.co.uk/ajax01/001.asp

If you type a number - e.g. 1 into the text field, and tab out of it, then 8 images are displayed. If you change the number, and tab out again, then the images are updated.

What I'd like to do is to have images to allow next / prev options, but I am stuck now!

I'm hoping to do this with basic hyperlinks, but I can't work out the syntax to get buttons / links / images which users can click, which will take them to the "background" 002.asp page - so rather than have to type a number, I'd like them to be able to click an image, and, for example, view the next 8 images.

I don't have a problem with the asp page to display the next 8 messages - my query is more about how to format the HTML / Javascript etc, to link in with the asp page - because I am trying to use AJAX to do the work in the background, rather than have a simple hyperlink, which would be dead easy...

Any help much appreciated... apologies for the vague query - I suppose I know what I'd like to do, and apart from my rather simplistic starting point, am not sure where to go from here.

Thanks

Jim
Mar 6 '08 #1
11 2569
acoder
16,027 Recognized Expert Moderator MVP
Use the code that you use to trigger the Ajax request in the onclick of the image, e.g.
Expand|Select|Wrap|Line Numbers
  1. onclick="sendRequest(...);"
Mar 7 '08 #2
burtonfigg
32 New Member
Thanks for the reply. Do you mean to take this, in the text input field:

Expand|Select|Wrap|Line Numbers
  1. onchange="sendRequest(this.form.email.value)
And to do something like:

Expand|Select|Wrap|Line Numbers
  1. <a href="#" onclick="sendRequest(this.form.email.value);">test</a>
This is where my lack of JavaScript experience shines through...

Because if I do this, how do I pass the value of the next / prev numbers through to the corresponding page that spits out the images?

Thanks

Jim
Mar 7 '08 #3
acoder
16,027 Recognized Expert Moderator MVP
Thanks for the reply. Do you mean to take this, in the text input field:

Expand|Select|Wrap|Line Numbers
  1. onchange="sendRequest(this.form.email.value)
And to do something like:

Expand|Select|Wrap|Line Numbers
  1. <a href="#" onclick="sendRequest(this.form.email.value);">test</a>
This is where my lack of JavaScript experience shines through...

Because if I do this, how do I pass the value of the next / prev numbers through to the corresponding page that spits out the images?
You're along the right lines. Replace the this.form.email.value with the next/prev number to pass to server script. Once a next/previous set of images is output, you may want to change a value which determines the current page. One idea is to use a global variable, current, and the next link would be current+1 and prev would be current-1. Of course, you need to disable previous when there's no previous page unless you cycle back to the last page.
Mar 7 '08 #4
burtonfigg
32 New Member
Thanks again for the advice.

I have put this in the javascript in the header:

Expand|Select|Wrap|Line Numbers
  1. var MyCurrentVar = 1;
  2. var incr = MyCurrentVar+1;
  3. var decr = MyCurrentVar-1;
And then this in the HTML:

[HTML]<p><a href="#" onclick="sendRequest(decr);">Prev</a> |
<a href="#" onclick="sendRequest(incr);">Next</a></p>[/HTML]That is working okay (it's online here) ... but I can't see how the values can keep increasing, or keep decreasing, because they are hard-coded in the javascript. i.e. if I click the 'Next' link, it works once, but doesn't keep on increasing...

Again, my poor javascripting I'm sure!

Thank you!
Mar 7 '08 #5
rnd me
427 Recognized Expert Contributor
Thanks again for the advice.
but I can't see how the values can keep increasing, or keep decreasing, because they are hard-coded in the javascript. i.e. if I click the 'Next' link, it works once, but doesn't keep on increasing...

try

Expand|Select|Wrap|Line Numbers
  1.  onclick="sendRequest(MyCurrentVar--);
  2. // instead of onclick="sendRequest(decr);
  3.  
and

Expand|Select|Wrap|Line Numbers
  1.  onclick="sendRequest(MyCurrentVar++);
  2. // instead of onclick="sendRequest(incr);
  3.  
you shouldnt need/use the extra vars, its the MyCurrentVar that you need to alter each time...
Mar 8 '08 #6
burtonfigg
32 New Member
That's great - thank you!

The next question, if it's okay to ask, is that when the user first lands on the page, there are no images in place, because unless the user clicks the next link, nothing is sent to the 002.asp page, which returns the images.

Do I need to initialise the page, or something, so that the images appear when the page is first viewed?

Thank you!
Mar 8 '08 #7
rnd me
427 Recognized Expert Contributor
edit body tag to simulate a click upon loading.


Expand|Select|Wrap|Line Numbers
  1. <body id="ajax01" onload="sendRequest(0)">
Mar 8 '08 #8
burtonfigg
32 New Member
Thank you very much!
Mar 8 '08 #9
burtonfigg
32 New Member
I have coded a very simple ajax page here:

http://jimpix.co.uk/ajax01/001.asp?cat=23

I have a few questions:

1. On first entering the page, is there any way I can disable the "prev" link?

2. When I hit the "next" button, it increments the "MyCurrentVar" variable by 1,and sends it to the underlying page that generates the images. But when I first hit the "next" button, nothing happens. I have to click it twice for the increment to seemingly take effect.

3. The SQL generates 12 images, using the "LIMIT" function in the SQL - e.g.:

SELECT photoID, photoName, image_type FROM j_ecard_photos WHERE catID = 23 LIMIT 9,12

But! If I click "Next" again, it only displays 11 images, because it starts running out of available ecards. Same again if I click Next again.

Is there any way I can check to see how many images remain (no problem with the SQL), and disable the "Next" button when there are <= 12?

Thanks

Jim
Mar 9 '08 #10
acoder
16,027 Recognized Expert Moderator MVP
Since this is related to your first thread, I have merged the two.
I have a few questions:

1. On first entering the page, is there any way I can disable the "prev" link?
You can have it set to return false onclick to begin with. Once Next is clicked, you can change this to enable prev. Alternatively, just show some text and replace it with a link when required (either using replaceChild() or hiding/showing the text/link).
Mar 10 '08 #11
rnd me
427 Recognized Expert Contributor
2. When I hit the "next" button, it increments the "MyCurrentVar" variable by 1,and sends it to the underlying page that generates the images. But when I first hit the "next" button, nothing happens. I have to click it twice for the increment to seemingly take effect.

set MyCurrentVar equal to one more in your code than you have it now.
Mar 10 '08 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

2
4139
by: Larry | last post by:
I am wondering if anyone has any thoughts on the following issues once Ajax is incorporated into a page: Now that we have this Ajax stuff, users have the potential to not leave a page for a long...
5
1750
by: darrel | last post by:
I've been playing with prototype.js and scriptaculous to create some nice drag-and-drop interaction on my applications GUI. That's working well. Now I want to take the next step and start passing...
3
5879
by: petermichaux | last post by:
Hi, I am trying to put together the last major pieces of my project's puzzle. This is more website/client-side architecture than JavaScript syntax but I hope this is a good place to ask. I'm a...
31
3073
by: Tony | last post by:
I just noticed that prototype.js is one of the files in the Ajax.NET distribution - I'm pretty concerned about this. Does anyone know if this is the same "prototype.js" that is not well-liked...
6
2512
by: Nico VanHaaster | last post by:
Hello all, I have run across an issue with IE 6.0+. I have a page that makes an XMLHttpRequest to the webserver to update a report on the page. The first time you hit the refresh report button...
1
1817
by: violinandviola | last post by:
I have just put 4 different ajax bits on this page: http://jimpix.co.uk/default-ajax.asp The ajax spits out chunks of images / news content, and users can view the chunks via next / prev links....
7
2281
by: Andy B | last post by:
I have a class I am creating for data access. I need to access controls from inside the class that are on a particular page. How do I do this? or is creating an instance of the page class and using...
7
6633
by: RichB | last post by:
I am trying to get to grips with the asp.net ajaxcontrol toolkit, and am trying to add a tabbed control to the page. I have no problems within the aspx file, and can dynamically manipulate a...
13
2190
by: burtonfigg | last post by:
I have a snippet of HTML here: <p><a title="" href="#pc" onclick="sendEcardRequest(prev_ecard());">Previous</a> | <a title="" href="#pc" onclick="sendEcardRequest(next_ecard());">Next</a></p> <p...
0
7203
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
7089
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
7282
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,...
1
6995
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
7463
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
5581
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 project—planning, coding, testing,...
1
5017
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...
0
4678
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...
0
1515
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 ...

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.