Forum     

Go Back   Digit Technology Discussion Forum > Portables, Peripherals and Electronics > QnA (read only)
Register FAQ Calendar Mark Forums Read

QnA (read only) Mods please help transfer the contents of this forum to proper sections. :)


 
 
LinkBack Thread Tools Search this Thread Display Modes
Old 21-02-2007, 02:36 AM   #1 (permalink)
In search of light...
 
abhi.eternal's Avatar
 
Join Date: Sep 2006
Location: Bangalore
Posts: 307
Thumbs down Help: JavaScript Code. Important!!!


hi. i need your help for developing a webpage.

i have created a table with 3 columns. now i want to load images (300*250) in the middle column from a particular folder. but they should be selected randomly. after an image is selected, by clicking it a new link (target: blank) should open.

i think this can be achieved through JScript. If there are 20 images in a folder, here is what I think should be the code structure:

1: Generate a random number between 1-20. say x.
2: If x=1, then <a href="link1" target="_blank"><img src="image1.gif" alt="image1" width="300" height="250" border="0" /></a>
If x=2, then <a href="link2" target="_blank"><img src="image2.gif" alt="image2" width="300" height="250" border="0" /></a>...
3: If x < 1 and X > 20 goto step1.

this is just the structure. please provide me the exact JScript codes to do what I intend and its implementation.

please help. i promise the sender of the first solution thats works will have a nice small surprise for him/her.

thank you.
__________________
http://abhijeetdeb.com
abhi.eternal is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 21-02-2007, 04:18 AM   #2 (permalink)
String Phreak
 
mediator's Avatar
 
Join Date: Mar 2005
Location: In ur Evil Mind!
Posts: 2,457
Default Re: Help: JavaScript Code. Important!!!

Since ur having a small surprise only for 1st part so here it is!

Quote:
<script>
function get_random()
{
var ranNum= Math.floor(Math.random()*20);
return ranNum;
}
</script>
This Generates numbers 0-19. U can ofcors just increment the variable to make it 1-20.

And please don't add such "bargain" like statements like "small surprise" next time!
__________________
Bad Bad server.....No candy for u!
mediator is offline  
Old 21-02-2007, 08:07 AM   #3 (permalink)
eWebGuru
 
ahref's Avatar
 
Join Date: Mar 2006
Location: Dehradun
Posts: 427
Default Re: Help: JavaScript Code. Important!!!

@mediator actually he want complete solution and not solution of generating random number only.

I don't think there is anything wrong, if he promise some gift for solution.
__________________
Windows and linux hosting at http://www.ewebguru.com
Get $50 per blog post PM me for details.
ahref is offline  
Old 21-02-2007, 01:37 PM   #4 (permalink)
In search of light...
 
abhi.eternal's Avatar
 
Join Date: Sep 2006
Location: Bangalore
Posts: 307
Default Re: Help: JavaScript Code. Important!!!

Full solutions only please.

Quote:
Originally Posted by mediator
And please don't add such "bargain" like statements like "small surprise" next time!
This is not a bargain. U don't know how much IMPORTANT this is for me!
__________________
http://abhijeetdeb.com
abhi.eternal is offline  
Old 21-02-2007, 02:08 PM   #5 (permalink)
String Phreak
 
mediator's Avatar
 
Join Date: Mar 2005
Location: In ur Evil Mind!
Posts: 2,457
Default Re: Help: JavaScript Code. Important!!!

^^I understand. I know its important to u. Thats why u cud have just said so.

Neways I hope this is wat u r looking for!
Quote:
<html>
<script>
function get_random()
{
var ranNum= Math.floor(Math.random()*20);
ranNum+=1;
return ranNum;
}
var x=get_random();
if (x==1) { window.open('http://www.yahoo.com')}
else if(x==2) { document.write('<a href="link2" target="_blank"><img src="image2.gif" alt="image2" width="300" height="250" border="0" /></a>')}
else document.write('Mediator is cool');

</script>
</html>
Observe the if-else statements and modify them as u wish!
__________________
Bad Bad server.....No candy for u!
mediator is offline  
Old 21-02-2007, 02:23 PM   #6 (permalink)
In search of light...
 
abhi.eternal's Avatar
 
Join Date: Sep 2006
Location: Bangalore
Posts: 307
Default Re: Help: JavaScript Code. Important!!!

thanx. i'll try it out.

but i have a few questions:

Quote:
{
var ranNum= Math.floor(Math.random()*20);
ranNum+=1;
return ranNum;
}
will these generate no.s between on 1-20?

please define these functions:

window.open
document.write

Quote:
else document.write('Mediator is cool');
no offense, but need that else it should again goto to the step to generate random numbers 1-20.

thanx for your prompt action.
__________________
http://abhijeetdeb.com
abhi.eternal is offline  
Old 21-02-2007, 02:51 PM   #7 (permalink)
String Phreak
 
mediator's Avatar
 
Join Date: Mar 2005
Location: In ur Evil Mind!
Posts: 2,457
Default Re: Help: JavaScript Code. Important!!!

Quote:
will these generate no.s between on 1-20?
Yes, and only bet. that range!



Quote:
1. window.open
2. document.write
1. to a open a new window with the given link
2. To write anything on the html page



Quote:
no offense, but need that else it should again goto to the step to generate random numbers 1-20.
Quote:
3: If x < 1 and X > 20 goto step1.
Such case (if entry) won't arise, so there is no need to goto step1.



Quote:
else document.write('Mediator is cool');
This code shud not be removed without orginal developer's consent!
__________________
Bad Bad server.....No candy for u!
mediator is offline  
Old 25-02-2007, 08:02 PM   #8 (permalink)
In search of light...
 
abhi.eternal's Avatar
 
Join Date: Sep 2006
Location: Bangalore
Posts: 307
Default Re: Help: JavaScript Code. Important!!!

Hey Mediator Check Your PM Inbox! You got my gift.
__________________
http://abhijeetdeb.com
abhi.eternal is offline  
Old 26-02-2007, 04:28 PM   #9 (permalink)
Wise Old Owl
 
piyush gupta's Avatar
 
Join Date: Sep 2005
Location: never land
Posts: 1,284
Default Re: Help: JavaScript Code. Important!!!

hey abhi i feel u need to understand basics of Javascript first before asking for some code

u asking for document.write and window.open
piyush gupta is offline  
Old 26-02-2007, 07:32 PM   #10 (permalink)
In search of light...
 
abhi.eternal's Avatar
 
Join Date: Sep 2006
Location: Bangalore
Posts: 307
Post Re: Help: JavaScript Code. Important!!!

Quote:
Originally Posted by piyush619
hey abhi i feel u need to understand basics of Javascript first before asking for some code

u asking for document.write and window.open
i dont have time to brush up JScript, thats why i asked for the codes.
__________________
http://abhijeetdeb.com
abhi.eternal is offline  
Old 03-03-2007, 03:36 PM   #11 (permalink)
Human Spambot
 
tuxfan's Avatar
 
Join Date: Feb 2004
Location: Mumbai
Posts: 2,653
Default Re: Help: JavaScript Code. Important!!!

Just one suggestions.

Instead of if .. else .. elseif, you should use switch case.
Code:
switch (x)
{
  case 1:
    statement 1;
    statement 2;
    break;
  case 2:
    statement 1;
    statement 2;
    break;
  case 3:
    statement 1;
    statement 2;
     break;
}
But if you just want to open an image based on the number and not do anything else, you don't even need a switch case!! You can do this.

Code:
  document.write("<a href='imgfull" + x + ".jpg' target=_blank><img src='img" + x + ".jpg'></a>");
(This code may have just some small syntax error of quotes which will be very easy to correct once you test it).

Any gift for optimised code?
__________________
:: Free hosting and free domain names available in special cases. Conditions apply ::
tuxfan is offline  
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


 
Latest Threads
- by Piyush
- by icebags
- by clinton
- by Charan

Advertisement




All times are GMT +5.5. The time now is 12:02 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2