faqts : Computers : Programming : Languages : JavaScript : Forms : SELECT

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

44 of 53 people (83%) answered Yes
Recently 6 of 10 people (60%) answered Yes

Entry

How can I indent OPTIONs, fill them with blanks?

Mar 5th, 2000 23:27
Martin Honnen,


Actually this page faqts use to enter knowledge base entries 
demonstrates how you can use the following character entity
   
to insert non breaking spaces into the OPTION text to format the OPTION 
appearance. So 
  <SELECT NAME="aSelect">
  <OPTION>Kibology
  <OPTION>&nbsp;&nsbp;Introduction
  <OPTION>&nbsp;&nbsp;&nbsp;&nbsp;Kibology for believers
  <OPTION>&nbsp;&nbsp;&nbsp;&nbsp;Kibology for atheists
  </SELECT>
gives you some indented OPTIONs.
If you use JavaScript do dynamically add an OPTION you have to use the 
character or character code equivalent to 
  &nbsp;
The character code is
  160
so 
  String.fromCharCode(160)
or
  '\u00A0'
is the character to use in a string. Example:

<FORM NAME="formName">
<A HREF="javascript: var select = document.formName.aSelect; 
         var option = 
           new Option (String.fromCharCode(160, 160, 160, 160) +
                       'Kibology for mensa members');
         select.options[select.options.length] = option;
         void 0
">
add an indented option
</A>

  <SELECT NAME="aSelect">
  <OPTION>Kibology
  <OPTION>&nbsp;&nbsp;Introduction
  <OPTION>&nbsp;&nbsp;&nbsp;&nbsp;Kibology for believers
  <OPTION>&nbsp;&nbsp;&nbsp;&nbsp;Kibology for atheists
  </SELECT>
</FORM>