to align right you can define a div and a css style for that
echo '<div class="alignRight">'.$strdocumento.'|</div>';
css
div.alignRight{
text-align:right;
width: 15ch;//to place same number of characters in a line
display: block;
float:;//you can add any css style to it and it works
}
EDIT
I know its not the perfect answer because Option elements cannot have any child elements but you can always go for alternative/pseudo select
plugin
if you want to do this in select without faking it than here is my code
it works correctly only if the font is monospaced (http://en.wikipedia.org/wiki/Monospaced_font)
<style type="text/css">
select { font-family: 'Courier',serif; }
</style>
define the select above js script so that it can identify the select
<select id="mySelect"></select>
now here place all your variables in an array and find the length of the longest string upto the character - "|" and subtract others with the longest string to add that many spaces
<script type="text/javascript">
// var string1 = '<?php //echo $strdocumento_1;?>';
// var string2 = '<?php //echo $strdocumento_2;?>';
var string1 = 'Lorem Ipsum alternative | Other Text';
var string2 = 'Lorem Ipsum | Other Text';
//you can use for loop or while loop in your php
var arrToFindLengthOfLongestString = [string1.substr(0, string1.indexOf('|')), string2.substr(0, string2.indexOf('|'))];
var longestLength = arrToFindLengthOfLongestString.sort(function (a, b) { return b.length - a.length; })[0].length;
for (var i = 0; i < arrToFindLengthOfLongestString.length; i++) {
for (var j = arrToFindLengthOfLongestString[i].length; j <= longestLength; j++) {
arrToFindLengthOfLongestString[i]=arrToFindLengthOfLongestString[i]+"\xa0";
}
arrToFindLengthOfLongestString[i] = arrToFindLengthOfLongestString[i]+"|";
// alert(arrToFindLengthOfLongestString[i]);
}
var arrForOption = [{
text: arrToFindLengthOfLongestString[0]+'your other text',//you can use loop if there are more variables
value: 'your value'
}, {
text: arrToFindLengthOfLongestString[1]+'your other text',//
value: 'yourvalue'
}];
var select = document.getElementById('mySelect');
// Iterate over array
arrForOption.forEach(function (obj, i) {
// Create new <option> with dynamic value and text
// Add the <option> to the <select>
select.appendChild(new Option(obj.text, obj.value));
});
</script>