views:

55

answers:

2

Hello guys,

I am buidling a small image navigator where the user inserts an image number and it has to load in the page so he can view it and do some processing on it later.

The images will be physically named 1,2,3,4,5.jpg for example.

Any quick code that i can use to make the corresponding image load

I know this is fairly simple - but i am pretty tight on deadline and would appreciate some code that works

thanks a lot in advance

+2  A: 

OK, use jquery. It is easy

Here is an example

HTML

<input type="text" id="imagenum" />
<a href="#" class="viewimage">View Image</a>
<img class="previewimage" src="">

The Script

$(document).ready(function() {

       $(".viewimage").click(function() {
          $(".previewimage").attr('src', "imagetopath\"+$("#imagenum").val()+".jpg");
       });

       //To catch the enter key
       $('#imagenum').keypress(function(event) {
          if (event.keyCode == '13') {
               $(".previewimage").attr('src', "imagetopath\"+$(this).val()+".jpg");
          }
       });

});
Starx
There's no JS (not to mention jQuery) in the sample provided. Actually it's not even functional.
Anax
@anax, It was not displayed due to editing
Starx
I am already using JQuery to add some cropping functionalities - donno how much JQUerying one object can handle :) - would appreciate a non-jquery solution
mireille raad
@mireille radd, jquery is an api, you dont need to worry about its efficiency, use jquery. A non-jquery solution, is a little time consuming, may be someone else will help you.
Starx
Thanks for ur help :) will try to implement ur solution :)
mireille raad
It should be simple to modify the code to load the image when the user presses the RETURN key (no need to grab the mouse). Can you add this, please?
Aaron Digulla
@aaron digulla, I have added it, see the answer again
Starx
Where is the +2 when you need it ... ;-)
Aaron Digulla
A: 
<img src="<?php print $ImgValue; ?>">

seems to work as an alternative to JQuery.

any other solution ?

mireille raad
Yes, this is definately an alternative, but you will need to sumbit the values(which is reload the page) every time user decides to navigate through image.
Starx