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

function displayPicture() question

Hey guys, I'm trying to make a function that will display a group of similarly named images. So far my js looks like this, the script is awful but the general idea is still present. I want the titles to display in order from 1 to 21. title1.jpg ,title2.jpg, title3.jpg , etc.
Is this even possible? or are there any better ways to accomplish this?
I've never done this before but i do know some javascript.
Thanks for all the responses in advance. You guys are geniuses.

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. function displayPicture()
  3. {
  4.       var imgNum ="title"+""+".jpg"+"<br />"
  5.       var imgMax = 21
  6.       if imgNum < imgMax,imgNum++,
  7.       <img src = imgNum height="" width=''">
  8. }
  9. </script>
Mar 9 '10 #1

✓ answered by RamananKalirajan

There are n no. of ways to do this. The way you have specified. It's a method we can do. But your code should be tuned.

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. function displayPicture()
  3. {
  4. var imgStr="";
  5. var imgMax = 21
  6. for(var i=1;i<-imgMax;i++)
  7.   imgStr+="<img src='title"+i+".jpg' height='' width='' /> <br/>";
  8. }
  9. </script> 

5 1568
RamananKalirajan
608 512MB
There are n no. of ways to do this. The way you have specified. It's a method we can do. But your code should be tuned.

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. function displayPicture()
  3. {
  4. var imgStr="";
  5. var imgMax = 21
  6. for(var i=1;i<-imgMax;i++)
  7.   imgStr+="<img src='title"+i+".jpg' height='' width='' /> <br/>";
  8. }
  9. </script> 
Mar 9 '10 #2
hmmm the code is still broken....and my validator isn't returning any errors
I made one change to the function you provided, because title's are inside another directory called "maps".... I'm not sure if the root file should be included or not
<img src='maps/title"+i...

Expand|Select|Wrap|Line Numbers
  1.  
  2. <script type="text/javascript">
  3.   function displayPicture()
  4.    {
  5.    var imgStr="";
  6.    var imgMax = 21
  7.    for(var i=1;i<-imgMax;i++)
  8.    imgStr+="<img src='maps/tit"+i+".jpg' height='200' width='200' /> <br/>";
  9.    }
  10.    </script> 
  11.  
Mar 9 '10 #3
Dormilich
8,658 Expert Mod 8TB
@Pr1nnyraid
should be
Expand|Select|Wrap|Line Numbers
  1.  <script type="text/javascript">
  2. function displayPicture()
  3. {
  4.     var i, imgStr = "",
  5.         imgMax = 21;
  6.     for (i = 1; i <= imgMax; i++) {
  7.         imgStr += "<img src='maps/tit" + i + ".jpg' height='200' width='200' /> <br/>";
  8.     }
  9.     return imgStr;
  10. }
  11. // somewhere else
  12. // container is the element, where the image string should be pasted
  13. container.innerHTML = displayPicture();
  14. </script> 
Mar 10 '10 #4
RamananKalirajan
608 512MB
Yep Dormilich, It's a typography error. It wont happen again.

Thanks and Regards
Ramanan Kalirajan
Mar 10 '10 #5
I fixed almost immediately after my second post. It works great now.At first I didn't think to add in another variable "i" but Ramanan cleared that up. Everytime I post here I'm always surprised at the quick responses and the level of programming skill you guys have.
Mar 10 '10 #6

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

Similar topics

20
by: modemer | last post by:
Question is as in subject. For example: class BaseClass { public: void func() { do something; } // I don't want this function being overloaded in its inherited class };
4
by: anonymous | last post by:
Thanks your reply. The article I read is from www.hakin9.org/en/attachments/stackoverflow_en.pdf. And you're right. I don't know it very clearly. And that's why I want to understand it; for it's...
0
by: Scott Wallace | last post by:
I have a page that displays several pictures pulled from a database. I want any one of the pictures to appear in a larger main picture container when the user clicks on it. I want to do this on the...
14
by: Mr Newbie | last post by:
I am often in the situation where I want to act on the result of a function, but a simple boolean is not enough. For example, I may have a function called isAuthorised ( User, Action ) as ?????...
7
by: Csaba Gabor | last post by:
I feel like it's the twilight zone here as several seemingly trivial questions are bugging me. The first of the following three lines is a syntax error, while the last one is the only one that...
3
by: Beta What | last post by:
Hello, I have a question about casting a function pointer. Say I want to make a generic module (say some ADT implementation) that requires a function pointer from the 'actual/other modules'...
43
by: Tony | last post by:
I'm working with GUI messaging and note that MFC encapsulates the message loop inside of a C++ class member function. Is this somehow inherently less robust than calling the message loop functions...
14
by: Pramod | last post by:
I have one question. Can I catch exception in function overloading.In my programm i want to create two function with same signature and same return type. I know its not possible...can i use...
9
by: CryptiqueGuy | last post by:
Consider the variadic function with the following prototype: int foo(int num,...); Here 'num' specifies the number of arguments, and assume that all the arguments that should be passed to this...
20
by: MikeC | last post by:
Folks, I've been playing with C programs for 25 years (not professionally - self-taught), and although I've used function pointers before, I've never got my head around them enough to be able to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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
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,...
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.