SunQuest
 
           Web Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsWeb DesignWeb Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old August 1st, 2004, 05:16 PM
brixie11 brixie11 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 6 brixie11 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 26 m 3 sec
Reputation Power: 0
Question Part of string

I have problem with part of string extraction. I'm developing a moviecard for eXtreme movie manager in HTML format.

Here is my problem:

I have a string variable "_MOVIE_GENRE_" in which can be entered for example "comedy/drama/action". I want to create script that for every genre will be inserted a gif pic.
That i do so far:

var genre="_MOVIE_GENRE_";
var comedy="<IMG src='moviecards/cortexmod/comedy.gif' border='0' align='absbottom' alt='comedy' width='25' high='12'>";
var drama="<IMG src='moviecards/cortexmod/drama.gif' border='0' align='absbottom' alt='drama' width='25' high='12'>";

switch(genre) {
case "Comedy":
document.all.genre.insertAdjacentHTML("AfterEnd",comedy);
break;
case "Drama":
document.all.genre.insertAdjacentHTML("AfterEnd",drama);
break;
}
.
.
.
.
Later in code i insert the gifs with:
&nbsp;<genre id="genre">

That works fine if the string is "comedy" OR "drama" but i want to insert two gifs if string in the var "_MOVIE_GENRE_" is "comedy/drama"

Any help will be welcome.

Thanx you all!

P.S. Forgive my english.

Reply With Quote
  #2  
Old August 1st, 2004, 10:09 PM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 4 m 48 sec
Reputation Power: 8
a more efficient way to write that might be:

Code:
var genre="_MOVIE_GENRE_";
var comedy="comedy.gif";
var drama="drama.gif";

document.all.genre.insertAdjacentHTML("AfterEnd","<IMG src='moviecards/cortexmod/"+comedy+"' border='0' align='absbottom' alt='comedy' width='25' height='12'>");


This stores less repetitive information in a variable.

As for the parsing of a string, you might want to look at Javascript's indexOf() function in combination with the substr() function. Then just pop them all into an array and use Javascript's for (var i in object) (equivalent to Perl's foreach structure) to print the HTML

Reply With Quote
  #3  
Old August 2nd, 2004, 02:44 AM
brixie11 brixie11 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 6 brixie11 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 26 m 3 sec
Reputation Power: 0
Another question

Thanx for quick reply.

Ive puted this together and i wonder if its ok:

var genre="_MOVIE_GENRE_";
var comedy="comedy.gif";
var drama="drama.gif";

var comedy1=genre.indexOf("Comedy");
if (comedy1 >= 0) {
document.all.genre.insertAdjacentHTML("AfterEnd","<IMG src='moviecards/cortexmod/"+comedy+" border='0' align='absbottom' alt='comedy' width='25' height='12'>");
}

Thanx.

Reply With Quote
  #4  
Old August 2nd, 2004, 09:08 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 4 m 48 sec
Reputation Power: 8
So long as it works, I guess its okay.

I was thinking something along the lines of searching for the index of the delimiting character, in your example it was a slash (/)... you can then form an array of the genres...

where is genre being set?

if you're setting it to "_MOVIE_GENRE_" then when would you ever find the word "Comedy"?

Reply With Quote
  #5  
Old August 3rd, 2004, 12:26 AM
brixie11 brixie11 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 6 brixie11 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 26 m 3 sec
Reputation Power: 0
I did it

I finaly put together my code. I never thought it is so simple. Here is what i did:

var genre="_MOVIE_GENRE_";
var separator=" - "
var comedy=genre.indexOf("Comedy");
if (comedy >= 0) {
document.all.genre.insertAdjacentHTML("AfterEnd","<IMG src='moviecards/cortexmod/comedy.gif' border='0' align='absbottom' alt='Comedy' width='30' height='30'>"+ separator);
}
var thriller=genre.indexOf("Thriller");
if (thriller >= 0) {
document.all.genre.insertAdjacentHTML("AfterEnd","<IMG src='moviecards/cortexmod/thriller.gif' border='0' align='absbottom' alt='Thriller' width='30' height='30'>"+ separator);
}
var action=genre.indexOf("Action");
if (action >= 0) {
document.all.genre.insertAdjacentHTML("AfterEnd","<IMG src='moviecards/cortexmod/action.jpg' border='0' align='absbottom' alt='Action' width='30' height='30'>"+ separator);
}
.
.
.
.
and so on...
Thanx for the tip.

P.S.: "_MOVIE_GENRE_" is a tag which this program eXtreme movie manager imports a contents of a field named "MOVIE GENRE" and tag "_TMOVIE_GENRE_" imports name of that field.
Brixie

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsWeb DesignWeb Development > Part of string


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway