<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: listbox code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sat, 17 May 2008 15:11:31 GMT</pubDate>
    <description>DZone Snippets: listbox code</description>
    <item>
      <title>date_select conversion</title>
      <link>http://snippets.dzone.com/posts/show/5376</link>
      <description>function to convert a value from a date_select into a more sql-friendly value&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;%=date_select(:date,'',:start_year =&gt; 1950,:include_blank =&gt; false, :default =&gt; { :year =&gt; '1970' })%&gt;&lt;br /&gt;&lt;br /&gt;def convert_date(obj) &lt;br /&gt;  return &#8220;#{obj[&#8216;(1i)&#8217;]}-#{obj[&#8216;(2i)&#8217;]}-#{obj[&#8216;(3i)&#8217;]}&#8221; &lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 17 Apr 2008 13:20:35 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5376</guid>
      <author>indiehead (John)</author>
    </item>
    <item>
      <title>Javascript QuickSelect (Coordinated Textbox And ListBox)</title>
      <link>http://snippets.dzone.com/posts/show/2629</link>
      <description>In HTML, say you have a select element with all the states.&lt;br /&gt;Unfortunately typing in this select box only works with the first letter.&lt;br /&gt;So if you type P then A you don't select pennsylvania.&lt;br /&gt;What I commonly do in this situation is to have what I call a quickselect textbox on the page as well.&lt;br /&gt;This is a textbox and listbox that are coordinated.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;// in your onload event handler you need this&lt;br /&gt;&lt;br /&gt;// hookup event handlers and control references&lt;br /&gt;var objElement = document.getElementById('cboState');&lt;br /&gt;if ( objElement )&lt;br /&gt;   {&lt;br /&gt;   objElement.onchange = QuickSelect_Change;&lt;br /&gt;   objElement.textbox = document.getElementById('txtState');&lt;br /&gt;   if ( objElement.textbox )&lt;br /&gt;      {&lt;br /&gt;      objElement.textbox.onchange = QuickSelect_TextChange;&lt;br /&gt;      objElement.textbox.onblur = QuickSelect_TextChange;&lt;br /&gt;      objElement.textbox.onkeypress = QuickSelect_KeyPress;&lt;br /&gt;      objElement.textbox.listbox = objElement;&lt;br /&gt;      }&lt;br /&gt;   }       &lt;br /&gt;&lt;br /&gt;// and now the functions&lt;br /&gt;&lt;br /&gt;// ----------------------------------------------------------------------------&lt;br /&gt;// QuickSelect_KeyPress&lt;br /&gt;//&lt;br /&gt;// Description : event handler for quick select textbox's key press event&lt;br /&gt;//    selects the appropriate item in the associated listbox control&lt;br /&gt;//&lt;br /&gt;// Arguments : none&lt;br /&gt;//&lt;br /&gt;// Dependencies : &lt;br /&gt;//&lt;br /&gt;// History :&lt;br /&gt;// 2006.09.20 - WSR : created&lt;br /&gt;//&lt;br /&gt;function QuickSelect_KeyPress( e )&lt;br /&gt;   {&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   var strCompare = '';&lt;br /&gt;   var numEntryLen;&lt;br /&gt;   var strEntry;&lt;br /&gt;   var objSelect = this.listbox;&lt;br /&gt;   var numOptions = objSelect.options.length;&lt;br /&gt;&lt;br /&gt;   var numCharCode;&lt;br /&gt;   var elTarget;&lt;br /&gt;&lt;br /&gt;   // get event if not passed&lt;br /&gt;   if (!e) var e = window.event;&lt;br /&gt;&lt;br /&gt;   // get character code of key pressed&lt;br /&gt;   if (e.keyCode) numCharCode = e.keyCode;&lt;br /&gt;   else if (e.which) numCharCode = e.which;&lt;br /&gt;&lt;br /&gt;   // get target&lt;br /&gt;   if (e.target) elTarget = e.target;&lt;br /&gt;   else if (e.srcElement) elTarget = e.srcElement;&lt;br /&gt;                                              &lt;br /&gt;   // if form input field &amp; it is a printable character&lt;br /&gt;   if ( elTarget.nodeName.toUpperCase() == 'INPUT' &amp;&amp; numCharCode &gt;= 32 &amp;&amp; numCharCode &lt;= 126 )&lt;br /&gt;      {&lt;br /&gt;&lt;br /&gt;      strEntry = this.value + String.fromCharCode(numCharCode);&lt;br /&gt;      numEntryLen = strEntry.length;&lt;br /&gt;&lt;br /&gt;      // cycle through options&lt;br /&gt;      for (var i = 0; i &lt; numOptions; i++)&lt;br /&gt;         {&lt;br /&gt;&lt;br /&gt;         // get compare string from value same length as entered string&lt;br /&gt;         strCompare = objSelect.options[i].value.substring(0, numEntryLen);&lt;br /&gt;&lt;br /&gt;         // if value matches what is entered&lt;br /&gt;         if (strEntry == strCompare)&lt;br /&gt;            {&lt;br /&gt;&lt;br /&gt;            // select this option&lt;br /&gt;            objSelect.options[i].selected = true;&lt;br /&gt;&lt;br /&gt;            // end loop&lt;br /&gt;            break;&lt;br /&gt;&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;         }&lt;br /&gt;&lt;br /&gt;      // I usually add an error class when input is required and not filled in&lt;br /&gt;      // this removes the class so the input is no longer marked as invalid&lt;br /&gt;      // commented out as it isn't necessary for general purpose&lt;br /&gt;      // RemoveClassName( this, 'error' );&lt;br /&gt;&lt;br /&gt;      }&lt;br /&gt;&lt;br /&gt;   }&lt;br /&gt;//&lt;br /&gt;// QuickSelect_KeyPress&lt;br /&gt;// ----------------------------------------------------------------------------&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;// ----------------------------------------------------------------------------&lt;br /&gt;// QuickSelect_TextChange&lt;br /&gt;//&lt;br /&gt;// Description : event handler for quick select textbox's change &amp; onblur events&lt;br /&gt;//    makes sure item in textbox is a value from list&lt;br /&gt;//&lt;br /&gt;// Arguments : none&lt;br /&gt;//&lt;br /&gt;// Dependencies : none&lt;br /&gt;//&lt;br /&gt;// History :&lt;br /&gt;// 2006.08.09 - WSR : created&lt;br /&gt;//&lt;br /&gt;function QuickSelect_TextChange()&lt;br /&gt;   {&lt;br /&gt;&lt;br /&gt;   var strCompare = '';&lt;br /&gt;   var numEntryLen = this.value.length;&lt;br /&gt;   var strEntry = this.value;&lt;br /&gt;   var objSelect = this.listbox;&lt;br /&gt;   var numOptions = objSelect.options.length;&lt;br /&gt;&lt;br /&gt;   // cycle through options&lt;br /&gt;   for (var i = 0; i &lt; numOptions; i++)&lt;br /&gt;      {&lt;br /&gt;&lt;br /&gt;      // get compare string from value same length as entered string&lt;br /&gt;      strCompare = objSelect.options[i].value.substring(0, numEntryLen);&lt;br /&gt;&lt;br /&gt;      // if value matches what is entered&lt;br /&gt;      if (strEntry == strCompare)&lt;br /&gt;         {&lt;br /&gt;&lt;br /&gt;         // select this option&lt;br /&gt;         objSelect.options[i].selected = true;&lt;br /&gt;&lt;br /&gt;         // end loop&lt;br /&gt;         break;&lt;br /&gt;&lt;br /&gt;         }&lt;br /&gt;&lt;br /&gt;      }&lt;br /&gt;&lt;br /&gt;   // copy code to textbox&lt;br /&gt;   this.value = this.listbox.options[this.listbox.selectedIndex].value;&lt;br /&gt;&lt;br /&gt;   // I usually add an error class when input is required and not filled in&lt;br /&gt;   // this removes the class so the input is no longer marked as invalid&lt;br /&gt;   // commented out as it isn't necessary for general purpose&lt;br /&gt;   // RemoveClassName( this, 'error' );&lt;br /&gt;&lt;br /&gt;   }&lt;br /&gt;//&lt;br /&gt;// QuickSelect_TextChange&lt;br /&gt;// ----------------------------------------------------------------------------&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;// ----------------------------------------------------------------------------&lt;br /&gt;// QuickSelect_Change&lt;br /&gt;//&lt;br /&gt;// Description : event handler for quick select list box's change event&lt;br /&gt;//    updates the textbox with the selected value&lt;br /&gt;//&lt;br /&gt;// Arguments: none&lt;br /&gt;//&lt;br /&gt;// Dependencies :&lt;br /&gt;//&lt;br /&gt;// History :&lt;br /&gt;// 2006.08.09 - WSR : created&lt;br /&gt;//&lt;br /&gt;function QuickSelect_Change()&lt;br /&gt;   {&lt;br /&gt;&lt;br /&gt;   // copy code to textbox&lt;br /&gt;   this.textbox.value = this.options[this.selectedIndex].value;&lt;br /&gt;&lt;br /&gt;   }	&lt;br /&gt;//&lt;br /&gt;// QuickSelect_Change&lt;br /&gt;// ----------------------------------------------------------------------------&lt;br /&gt;  &lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;</description>
      <pubDate>Wed, 20 Sep 2006 21:31:48 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2629</guid>
      <author>Will_Rickards (Will Rickards)</author>
    </item>
    <item>
      <title>Using icons in Listbox</title>
      <link>http://snippets.dzone.com/posts/show/422</link>
      <description>pys60 1.1.3 provide some graphics capabilitis.&lt;br /&gt;One of them is using icons in Listbox&lt;br /&gt;(code taken from pys60 API reference)&lt;br /&gt;&lt;code&gt;&lt;br /&gt;icon1 = appuifw.Icon(u"z:\\system\\data\\avkon.mbm", 28, 29)&lt;br /&gt;icon2 = appuifw.Icon(u"z:\\system\\data\\avkon.mbm ", 40, 41)&lt;br /&gt;entries = [(u"Signal", icon1),&lt;br /&gt;           (u"Battery", icon2)]&lt;br /&gt;lb = appuifw.Listbox(entries, lbox_observe)&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Listbox is one of the 3 types that can be assigned to app.body&lt;br /&gt;(i.e. Text, Listbox, Canvas)&lt;br /&gt;So, to make code above able to run, you must add&lt;br /&gt;&lt;code&gt;appuifw.app.body = lb&lt;/code&gt;&lt;br /&gt;and the function lbox_observe that will handle the selection&lt;br /&gt;need to be defined.</description>
      <pubDate>Fri, 01 Jul 2005 15:24:44 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/422</guid>
      <author>korakot (Korakot Chaovavanich)</author>
    </item>
  </channel>
</rss>
