Saving space in HTML selection option

I have a set of html text fields that enter input and when the user clicks the add button, uses javascript to enter text and format the string placed in the HTML select box. The first of these boxes must contain 2 characters, but can also take a space. Formatted lines will look like this:

  01-ABC-O
 02-def-i

However, I need a way to display empty numbers that line up with other elements

  -GHI-O

This type of record will display fine when javascript adds this parameter, but when the page reloads and the selection is populated with values ​​(I use Java, jsp and struts 1.1 if this helps), it gets the same values ​​(spaces remain), but the spaces are larger don't appear in the select control (I was looking at the source of the page and it looks identical to when javascript adds this option). I tried replacing spaces for   but it just prints the string "& nbsp" instead of space. I also tried using the "pre" html blocks and the css white-space property and did not work.

Let me know if further clarification is required.

+6
source share
5 answers

You need to replace the spaces with   , and it should work - pay attention to the closing half-time (which is missing in your example in the question)! When you do this through Javascript, most (all?) Browsers will automatically display spaces, but when spaces are loaded there, all (sometimes all but one) of them will be ignored.

You must also apply the font-family: CSS attribute to the selection element, which indicates fonts with a monolayer, to ensure that all elements are correctly aligned.

+7
source

You can use the pre css style in the area where you are pointing the value.

 <style type="text/css"> #element { white-space: pre; } </style> <div id="element"> stuff goes here </div> 

This will save all the spaces in the div element (other types of elements will also work), and you do not need to worry about using unused space.

+1
source

Are you going to add it using scripts, you need to use Escape codes for Space "% A0", which you then decode using unescape ()

 logTypeList[i] = new Option(unescape(" kent Agent".replace(/ /g, "%A0")), "theValue"); 
+1
source

You can use the UNIQUE SPACE character (U + 0020) instead of &nbsp; ("\ u0020")

0
source
 logTypeList[i] = new Option(unescape(" kent Agent".replace(/ /g, "%A0")), "theValue"); 

Since unescape is deprecated, you can use decodeURI:

 logTypeList[i] = new Option(decodeURI(" kent Agent".replace(/ /g, "%C2%A0")), "theValue"); 

Additional information at http://www.javascripter.net/faq/mathsymbols.htm

0
source

Source: https://habr.com/ru/post/899562/


All Articles