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>\r\n';
txt+='</entry>\r\n';
txt+='\r\n';
...
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
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
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).
Code:
function htmlentities(s)
{
return s.replace(/[^\w ]/g, function (s) {return '&#' + s.charCodeAt(0) + ';'; });
}
For the first one, you can probably replace what is inside the FOR-loop with:
Code:
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);
Regarding the diacritic signs ... unfortunately the code was interpreted and for instance in my sentence the &#233; were converted into é
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 é à ç ... but with &#233; &#224; &#231; codes instead
Bookmarks