473,411 Members | 2,031 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

getting 'options' is null or not an object using autoComplete with dynamic dataset

I am getting 'options' is null or not an object using when using a dynamic dataset with a dropdown list in an html form. I am filling-in a text field and filtering the values in the drop-down. This functionality works with a fixed set of values in the drop-down (i.e. <option value tags). Any insight would be greatly appreciated.

Expand|Select|Wrap|Line Numbers
  1.   <INPUT TYPE="text" NAME="input1" VALUE="" ONKEYUP="autoComplete(this,this.form.OBDataSet__135_1,'value',true)">
  2. <select size="1" name="OBDataSet__135_1" onChange="this.form.input1.value=this.options[this.selectedIndex].value">
  3. </select></td>
  4.  
  5.  
  6. <script>
  7.  
  8.     function autoComplete (field, select, property, forcematch) {
  9.     var found = false;
  10.        alert("field " + field.value);
  11.        // alert("select " + select.options[i][property]);
  12. alert("property " + property);
  13. alert("forcematch " + forcematch);
  14. alert("index" + document.form1.OBDataSet__135_1.selectedIndex);
  15. alert("text" + document.form1.OBDataSet__135_1.options[0].text);
  16.     for (var i = 0; i < select.options.length; i++) {
  17.        //for (var i = 0; i < 4; i++) {
  18.     if (select.options[i][property].toUpperCase().indexOf(field.value.toUpperCase()) == 0) {
  19.         found=true; break;
  20.         }
  21.     }
  22.     if (found) { select.selectedIndex = i; }
  23.     else { select.selectedIndex = -1; }
  24.     if (field.createTextRange) {
  25.         if (forcematch && !found) {
  26.             field.value=field.value.substring(0,field.value.length-1); 
  27.             return;
  28.             }
  29.         var cursorKeys ="8;46;37;38;39;40;33;34;35;36;45;";
  30.         if (cursorKeys.indexOf(event.keyCode+";") == -1) {
  31.             var r1 = field.createTextRange();
  32.             var oldValue = r1.text;
  33.             var newValue = found ? select.options[i][property] : oldValue;
  34.             if (newValue != field.value) {
  35.                 field.value = newValue;
  36.                 var rNew = field.createTextRange();
  37.                 rNew.moveStart('character', oldValue.length) ;
  38.                 rNew.select();
  39.                 }
  40.             }
  41.         }
  42.     }
  43.  
  44.  
  45. </script>
  46.  
Oct 25 '06 #1
5 11935
iam_clint
1,208 Expert 1GB
you can try using document.GetElementById
put an id on the select box and use the get element by id instead of document.form

this may fix your problem.
Oct 25 '06 #2
I appreciate you patience with this. Would you be willing to help me with the syntax of using your code with the code I have provided? I have tried GetElementById a few different ways, and continue to get errors.
Oct 26 '06 #3
iam_clint
1,208 Expert 1GB
Heres what I got for you bud, hope this helps you out let me know your results.
Expand|Select|Wrap|Line Numbers
  1. <INPUT TYPE="text" NAME="input1" id="input1" VALUE="" ONKEYUP="autoComplete(this,document.getElementById('OBDataSet__135_1'),'value',true)">
  2. <select size="1" name="OBDataSet__135_1" id="OBDataSet__135_1" onChange="document.getElementById('input1').value=this.options[this.selectedIndex].value">
  3. <option>Test</option>
  4. <option>Apple</option>
  5. <option>Candy</option>
  6. <option>Corn</option>
  7. </select></td>
  8.  
  9.  
  10. <script>
  11.  
  12.     function autoComplete (field, select, property, forcematch) {
  13.     var found = false;
  14. //alert("index" + document.getElementById("OBDataSet__135_1").selectedIndex);
  15. //alert("text" + document.getElementById("OBDataSet__135_1").options[0].text);
  16.     for (var i = 0; i < select.options.length; i++) {
  17.     if (select.options[i].text.toUpperCase().indexOf(field.value.toUpperCase()) == 0) {
  18.         found=true; 
  19.                 break;
  20.         }
  21.     }
  22.     if (found) { select.selectedIndex = i; }
  23.     else { select.selectedIndex = -1; }
  24.     if (field.createTextRange) {
  25.         var cursorKeys ="8;46;37;38;39;40;33;34;35;36;45;";
  26.         if (cursorKeys.indexOf(event.keyCode+";") == -1) {
  27.             var r1 = field.createTextRange();
  28.             var oldValue = r1.text;
  29.             var newValue = found ? select.options[i].text : oldValue;
  30.             if (newValue != field.value) {
  31.                 field.value = newValue;
  32.                 var rNew = field.createTextRange();
  33.                 rNew.moveStart('character', oldValue.length) ;
  34.                 rNew.select();
  35.                 }
  36.             }
  37.         }
  38.     }
  39.  
  40.  
  41. </script>
  42.  
Oct 26 '06 #4
Yes, the use of "options[i].text" vs. "options[i][property]" work. I very much appreciate the help. Can you tell me why this work?

-- new
select.options[i].text.toUpperCase().

-- old
select.options[i][property].toUpperCase()
Oct 30 '06 #5
iam_clint
1,208 Expert 1GB
i don't know what [Property] does or is so i removed it form the code and works like a charm... thats incorrect syntax.
Oct 30 '06 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Joe | last post by:
Hi All, I am new to using the Access DB and I need some help if someone is able to give it to me. What I want to do is get the names of the columns of certain tables. Not the data in the table...
0
by: Noah Coad [MVP & MCP] | last post by:
When working with a DataSet generated from a DataSet definitions file (.xsd file), AutoComplete works fine for the first few times I press . after a class, but it stops completing text usually...
1
by: mlarson | last post by:
Hello, I'm working on a page that dynamically creates listboxes and the "options" that are added to the listbox. A user can then click on buttons to either add or delete the "options" from one...
6
by: Brett | last post by:
Not sure what the problem is here... Trying to update from a datagrid to an access database using vb.net... Its not updating the database but Im not getting any errors... Here is my code... ...
1
by: Jerry John | last post by:
I am working in ASP.NET with C#. I have a text file which contains datas with delimiters. For example:- MSH|^~\$|DISCHARGE|CLAY COUNTY MEMORIAL|||200502110939| I also have an XML file created...
2
by: jdzemke | last post by:
I am trying to validate that a null value is not chosen from a dynamic dataset called "OBDataSet__135_1" when a form Submit operation is performed. To do this I have a javascript function called...
41
by: Jim | last post by:
Hi guys, I have an object which represents an "item" in a CMS "component" where an "item" in the most basic form just a field, and a "component" is effectively a table. "item" objects can be...
3
by: renjucool | last post by:
I am developing an online bug tracking system in asp.net.IT is implemented now in our office,at a time around 10-15 peoples are using.Web application is hosted in a local machine(core 2duo-1 gb...
2
by: rocketfire97 | last post by:
I'm trying to call a COM object using C# but having no luck getting values back for passed in ref objects. I've tried the same call using VB.NET and can get data back. How would I implement the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.