[JavaScript] select box question

Ian Skinner ian.skinner at bloodsource.org
Thu Jan 6 15:06:44 CST 2005


Remember that HTML collapses multiple white spaces into one.  You may need to be using a non-breaking-space character entity there.  Trying putting an   in your string for each white space character you want.


--------------
Ian Skinner
Web Programmer
BloodSource
www.BloodSource.org
Sacramento, CA

"C code. C code run. Run code run. Please!"
- Cynthia Dunning



...-----Original Message-----
...From: tyson [mailto:twenger at vltool.com]
...Sent: Thursday, January 06, 2005 12:43 PM
...To: [JavaScript List]
...Subject: Re: [Javascript] select box question
...
...I want to be able to add a value into my selectbox from javascript that
...will have more than one blank space between characters.  The demo that
...you gave to me did that, but it only shows the blank spaces when I click
...on the select box.  When I'm not clicking on the select box, the blank
...spaces are not shown.
...For example, I would want this string  "hello     world" to be shown in
...the select box with those 5 spaces in between.  .
...
...Shawn Milo wrote:
...
...>Please explain more clearly. What is it you want to have happen?
...>
...>Shawn
...>
...>
...>
...>>I tried your test and it works, but it only shows the added spaces when
...>>you click on the select box. I need those blank spaces shown all the
...>>time, even when the user isn't clicking on it.  Is there some way to
...get
...>>that working?
...>>
...>>Shawn Milo wrote:
...>>
...>>
...>>
...>>>Tyson:
...>>>
...>>>Hi. You can use CSS to do this:
...>>>document.forms[0].my_select_box[document.forms[0].my_select_box.length
...- 1].style.wordSpacing = '5em';
...>>>
...>>>
...>>>Full working and tested HTML below.
...>>>
...>>>Shawn
...>>>
...>>>
...>>>
...>>>
...>>><html>
...>>><head>
...>>>
...>>><title>Javascript Test</title>
...>>>
...>>><script type="text/javascript">
...>>>
...>>>
...>>>  function testStuff(){
...>>>
...//document.forms[0].my_select_box.options[document.forms[0].my_select_box
....length] = new Option('hello        hi');
...>>>
...//document.forms[0].my_select_box.options[document.forms[0].my_select_box
....length] = new Option('hello &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; hi');
...>>>
...document.forms[0].my_select_box.options[document.forms[0].my_select_box.l
...ength] = new Option('hello hi');
...>>>
...>>>
...document.forms[0].my_select_box[document.forms[0].my_select_box.length -
...1].style.backgroundColor = '#fad762';
...>>>
...document.forms[0].my_select_box[document.forms[0].my_select_box.length -
...1].style.fontSize = '17pt';
...>>>
...document.forms[0].my_select_box[document.forms[0].my_select_box.length -
...1].style.wordSpacing = '5em';
...>>>  }
...>>>
...>>></script>
...>>></head>
...>>>
...>>><body>
...>>>
...>>>  <form id="testForm" method="post" action="./test.html">
...>>>
...>>>     <select id="my_select_box">
...>>>        <option value="0">0</option>
...>>>        <option value="1">1</option>
...>>>
...>>>     </select>
...>>>
...>>>     <input type="button" id="btnTest" value="This is a test."
...onclick="testStuff();" />
...>>>  </form>
...>>>
...>>></body>
...>>>
...>>>
...>>>
...>>>
...>>>
...>>>
...>>>
...>>>
...>>>>Hi-
...>>>>  When I add an item into my select box through javascript, I want
...>>>>multiple blank spaces to be kept in the string that's being added.
...For
...>>>>some reason it only allows one blank space at a time. Here's my code-
...>>>>
...>>>>##########
...>>>>document.forms[0].my_select_box.options[document.forms[0].my_select_b
...ox.length]
...>>>>= new Option ('hello     hi')
...>>>>##########
...>>>>
...>>>>There should be five spaces between the 'hello' and 'hi', but only
...one
...>>>>blank space shows up in the select box.  I've tryed adding the spaces
...>>>>with the char_code, that doesn't work.  I've also tryed adding spaces
...>>>>with &nbsp, and that doesn't work.  Any help would be appreciated.
...>>>>
...>>>>_______________________________________________
...>>>>Javascript mailing list
...>>>>Javascript at LaTech.edu
...>>>>https://lists.LaTech.edu/mailman/listinfo/javascript
...>>>>
...>>>>
...>>>>
...>>>>
...>>>>
...>>>_______________________________________________
...>>>Javascript mailing list
...>>>Javascript at LaTech.edu
...>>>https://lists.LaTech.edu/mailman/listinfo/javascript
...>>>
...>>>
...>>>
...>>>
...>>>
...>>_______________________________________________
...>>Javascript mailing list
...>>Javascript at LaTech.edu
...>>https://lists.LaTech.edu/mailman/listinfo/javascript
...>>
...>>
...>>
...>_______________________________________________
...>Javascript mailing list
...>Javascript at LaTech.edu
...>https://lists.LaTech.edu/mailman/listinfo/javascript
...>
...>
...>
...
..._______________________________________________
...Javascript mailing list
...Javascript at LaTech.edu
...https://lists.LaTech.edu/mailman/listinfo/javascript

Confidentiality Notice:  This message including any
attachments is for the sole use of the intended
recipient(s) and may contain confidential and privileged
information. Any unauthorized review, use, disclosure or
distribution is prohibited. If you are not the
intended recipient, please contact the sender and
delete any copies of this message. 





More information about the Javascript mailing list