473,395 Members | 1,653 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,395 software developers and data experts.

Error with calling getElementByID call from a dynamic list

82
Hi,

I am creating dynamic list in the server through php and insert it using ajax.

for ajax I using the following statement:

document.getElementById(list_name_id).innerHTML=xm lHttp.responseText ;

until now everything is OK the list is builds correctly. but when I use the
document.getElementById(call_list_id).options.valu e I got an error saing "value is null or it is not an object" It seems that object list ID is null. Although when I was created the list I added a statement to the select "id=xxx".

Any suggestions how to solve this issue.

Here is my code:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2.  
  3. <head>
  4.  
  5. <title></title>
  6. <script language="javascript" type="text/javascript">
  7.  
  8. var last_model_category_selected="none";
  9. var last_manufacture_selected="none";
  10. var last_model_type_selected="none";
  11. var last_model_name_selected="none";
  12. var url_base="http://192.168.2.6:8080/src/autocomplete/create_generic_listbox.php?";
  13.  
  14. function buildList(call_list_id,list_name_id)
  15. //call_list_id - The  div that calls the function
  16. //list_name_id - the id of the list to be created
  17. // 
  18. // Remember the value select in category list
  19.  
  20. var url;
  21.  
  22. if (call_list_id == "modelCategory" ) { 
  23.          last_model_category_selected=document.getElementById(call_list_id).options.value ;
  24.          url=url_base+"isEmpty=FALSE&list_type=manufacture&last_selected="+last_manufacture_selected+"&   list_dependency_1="+last_model_category_selected+"&list_dependency_2=''&list_dependency_3=''" ;
  25. //         alert(last_model_category_selected);
  26. } else if (call_list_id == "manufacture") {
  27. //alert(call_list_id);
  28.          last_manufacture_selected=document.getElementById(call_list_id).options.value ;
  29.  
  30.          url=url_base+"isEmpty=FALSE&list_type=model_type&last_selected="+last_model_type_selected+"&   list_dependency_1="+last_model_category_selected+"&list_dependency_2="+last_manufacture_selected+"&list_dependency_3=''" ;
  31. } else if (call_list_id == "modelType") {
  32.         last_model_type_selected=document.getElementById(call_list_id).options.value ;
  33.          url=url_base+"isEmpty=FALSE&list_type=model_type&last_selected="+last_model_type_selected+"&   list_dependency_1="+last_model_category_selected+"&list_dependency_2="+last_manufacture_selected+"&list_dependency_3="+last_model_type_selected ;
  34. } else {
  35.   return FALSE;
  36. }
  37.  
  38. // Perform Ajax request
  39.  
  40.        xmlHttp=GetXmlHttpObject(); 
  41.  
  42.         if (xmlHttp==null)
  43.          {
  44.            alert ("Your browser does not support AJAX!");
  45.            return FALSE;
  46.          }  
  47.  
  48.            xmlHttp.onreadystatechange = function() {
  49.            if (xmlHttp.readyState == 4 && xmlHttp.status==200) {        
  50.             document.getElementById(list_name_id).innerHTML=xmlHttp.responseText ;
  51.            }
  52.            };
  53.            xmlHttp.open("GET", url); 
  54.            xmlHttp.send(null);
  55.  
  56.  
  57.  
  58. }
  59.  
  60.  
  61. function GetXmlHttpObject()
  62. {
  63. var xmlHttp=null;
  64. try
  65.   {
  66.   // Firefox, Opera 8.0+, Safari
  67.   xmlHttp=new XMLHttpRequest();
  68.   }
  69. catch (e)
  70.   {
  71.   // Internet Explorer
  72.   try
  73.     {
  74.     xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  75.     }
  76.   catch (e)
  77.     {
  78.     xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  79.     }
  80.   }
  81. return xmlHttp;
  82.  
  83. }
  84.  
  85. </script>
  86.  
  87.  
  88. </head>
  89.  
  90. <body oninit=buildLists();>
  91. <form id="productSelector">
  92. <div id="modelCategoryDiv" > </div>
  93. <select name="modelCategory" id="modelCategory" style="width:130" onchange="buildList('modelCategory','manufacture')">
  94.   <option value="none" selected >none</option>
  95.   <option value="x"  >x</option>
  96.   <option value="y" >y</option>
  97.   <option value="z">z</option>
  98.   <option value="t">t</option>
  99. </select>
  100. <div id="manufacture"> </div>
  101. <div id="modelType"> </div>
  102. <div id="modelName"> </div>
  103.  
  104. </form>
  105. </body>
  106. </html>


Thanks
Ronen
Mar 9 '08 #1
4 2229
hsriat
1,654 Expert 1GB
options is an array.
If you have to use it, then you may need to use options[index].value.

If you want to know the current select value of the select box, use selectObject.value
Mar 9 '08 #2
raknin
82
options is an array.
If you have to use it, then you may need to use options[index].value.

If you want to know the current select value of the select box, use selectObject.value
Thanks, I have the same issue the select id is null for some reason.You can try it yourself.
Mar 9 '08 #3
raknin
82
I tried even:
Expand|Select|Wrap|Line Numbers
  1. last_manufacture_selected=document.getElementById('manufacture').options[document.getElementById('manufacture').options.selectedIndex].value;
  2.  
But still have the same error not an object or has null value.

It is look like that when you create the list on the server it display but you can not manipulate it.
Mar 9 '08 #4
hsriat
1,654 Expert 1GB
I tried even:
Expand|Select|Wrap|Line Numbers
  1. last_manufacture_selected=document.getElementById('manufacture').options[document.getElementById('manufacture').options.selectedIndex].value;
  2.  
But still have the same error not an object or has null value.

It is look like that when you create the list on the server it display but you can not manipulate it.
try this:
Expand|Select|Wrap|Line Numbers
  1. last_manufacture_selected = document.getElementById('manufacture').value;
Mar 10 '08 #5

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

Similar topics

1
by: Wayno | last post by:
My php logs are coming up empty. I have done all I can think of, and all that made sense to me. Can someone take a look at my php.ini please and tell me what you think may be the problem. I...
1
by: Red Ogden | last post by:
The following script returns an error saying document.all is null or not an object when I try to call the write_layer function more than once within the same else statement i.e.: else {...
5
by: Francesco Bochicchio | last post by:
Hi all, anybody knows if there is a (standard, portable) way to dinamically build a list of parameters to call a C function? Something like va_start & co, but to be used on the calling side? ...
1
by: kamleshsharmadts | last post by:
I am using Ajax with struts in web application. from jsp i am calling a function of ajax.js onclick of a button. code of that call function which calling from jsp given as below:- ...
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...
5
by: Bjorn Sagbakken | last post by:
Hello I have just migrated from VS 2003 to VS 2005, and .NET framework 1.1 to 2.0 I am at the end of debugging and fixing stuff. Now there is one error I just cannot find a solution to: On...
1
by: Memphis Steve | last post by:
Is it possible to combine multiple javascipts into one file and then call that file from a linked URL in the head section of an XHTML file? Here are the two scripts I want to use with the...
10
by: james_027 | last post by:
hi, i have a function that I could like to call, but to make it more dynamic I am constructing a string first that could equivalent to the name of the function I wish to call. how could I do...
9
by: ahilar12 | last post by:
1. <head> 2. <script type="text/javascript"> 3. </script> 4. </head> 5. <body> 6. <form> 7. <select name="team" id="mylist" > 8. <option></option> 9....
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...

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.