/    Sign up×
Community /Pin to ProfileBookmark

please help me simplifying my code …

Hi (I am not a native-English speaker),

I prepared a RSS generator to display information on the online journal I am editing

I am not familiar with javascript but I managed to get something that works

I would like to control the number of rows visible with respect to the “authors” item

1 row visible if only one author, 2 for 2, 3 for 3 … with a tool to select the number of rows to display.

the problem is that the display of the generated list of authors should vary depending on the number of authors

author1
author1 & author2
author1, author2 & author3

author1, author2, author3 & author4

May be it can be done with a do while (I used a set of if else which limited me to 6 “authors” rows always visible)

[url]http://paleopolis.rediris.es/cg/generator_RSS2.html[/url]

There should be a “smart” way …

Thank you in advance for your appreciated help,
Bruno

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@voidvectorDec 15.2008 — The following code loops from 1 thru N, add the authors to an array. It then join the array using the join() function, then replace the last comma with a ampersand using RegExp.

Don't think it's more efficient. Might be cleaner

[CODE]
...
txt+=' <summary>';

var authorlist = new Array();
for (var i = 1; i <= form.auteurs.options[form.auteurs.selectedIndex].text; i ++)
{
authorlist.push(form['author' + i + 'B'].value + ' ' + form['author' + i + 'C'].value + ' ' + form['author' + i + 'A'].value);
}

var authors = authorlist.join(', ').replace(/,([^,]*)$/, ' &$1');

txt+= authors + '.- ' + form.title.value + '.- ' + form.abstract.value + '.- SRef-ID: http://overview.sref.org/1634-0744/CG' + form.year.options[form.year.selectedIndex].text + '_' + cat + form.issue.value + '.- Handle-ID: http://hdl.handle.net/2042/' + form.handle.value + '</summary>rn';
txt+='</entry>rn';

txt+='rn';
...
[/CODE]
Copy linkTweet thisAlerts:
@bruno2009authorDec 15.2008 — Many thanks: it is really amazing how it works fine!

I only change the & for a & as I want it to be understood by a RSS feed (a single & will stack it)

Can you help me with the 2nd part of my quthe estion?

that is how to select or better to enter a number of authors that would generate one data entry line for each (the default being 1 author, i.e. 1st author, = 1 line)?

Can I ask one more thing to even get a better result!?...

there are many "diacritic signs" in Spanish, French, Italian, ...

and I would like to get a "clean" final text, that is without é à ç ... but with é à ç codes instead ...

I suppose I have to insert something before the final

form.result.value=txt;}
Copy linkTweet thisAlerts:
@bruno2009authorDec 15.2008 — Many thanks: it is really amazing how it works fine!

I only change the & for a & as I want it to be understood by a RSS feed (a single & will stack it)

I posted the new version under

http://paleopolis.rediris.es/cg/generator_RSS2VV.html

Can you help me with the 2nd part of my question?

that is how to select or better to enter a number of authors that would generate one data entry line for each (the default being 1 author, i.e. 1st author, = 1 line)?

Can I ask one more thing to even get a better result!?...

there are many "diacritic signs" in Spanish, French, Italian, ...

and I would like to get a "clean" final text, that is without é à ç ... but with é à ç codes instead ...

I suppose I have to insert something before the final

form.result.value=txt;}
Copy linkTweet thisAlerts:
@voidvectorDec 16.2008 — For diacritics, use this function, pass any string to it, it will convert all characters that is not English-word character or space to HTML entity (number-based).
<i>
</i>function htmlentities(s)
{
return s.replace(/[^w ]/g, function (s) {return '&amp;#' + s.charCodeAt(0) + ';'; });
}


For the first one, you can probably replace what is inside the FOR-loop with:
<i>
</i>if (form['author' + i + 'B'].value || form['author' + i + 'C'].value || form['author' + i + 'A'].value)
authorlist.push(form['author' + i + 'B'].value + ' ' + form['author' + i + 'C'].value + ' ' + form['author' + i + 'A'].value);
Copy linkTweet thisAlerts:
@bruno2009authorDec 16.2008 — Regarding the diacritic signs ... unfortunately the code was interpreted and for instance in my sentence the &#038;#233; were converted into &#233;

it should have read

there are many "diacritic signs" in Spanish, French, Italian, ...

and I would like to get a "clean" final text, that is without &#233; &#224; &#231; ... but with &#038;#233; &#038;#224; &#038;#231; codes instead
×

Success!

Help @bruno2009 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...