Hi. I don't know where the problem is. The next codes is working on Google Chome but not in IE. I haven't tested yet on Firefox.


function getSheetCount() {
	var xmlhttp;
	if (window.XMLHttpRequest){
		xmlhttp=new XMLHttpRequest();
	else {
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4 && xmlhttp.status==200) {
			var txt = xmlhttp.responseText;
			for(i=0; i<parseInt(txt); i++){
				document.getElementById('sheetNo').innerHTML+="<option value=\""+ i +"\">"+(i+1)+"</option>";


	require_once 'Classes/PHPExcel.php';
	$inputFileName = 'rf1.xls';
	$objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
	echo $objPHPExcel->getSheetCount();


<label>Sheet no:</label><select name="sheetNo" id="sheetNo"></select>

I tried prompting a dialog box on getSheetCount and it shows this error

Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET4.0C)
Timestamp: Mon, 23 May 2011 09:52:49 UTC

Message: 'document.getElementById(...)' is null or not an object
Line: 152
Char: 5
Code: 0
URI: http://localhost/final/javascript/functions.js

By the way, I am using Internet Explorer 8.

Please help me,

Recommended Answers

All 3 Replies

You need to put that function call in window.onload.

Hi twiss,

Thanks for the reply. It does not work either. What I did was I called the function on body tag, like this.

<body onload="startup()">
function startup(){
	//load startup functions

When I tried to prompt the values I need, it executes it correctly. I also tried prompting a dialog box inside the loop on getSheetCount function and it shows the value correctly. I think the problem was on this code.

document.getElementById('sheetNo').innerHTML+="<option value=\""+ i +"\">"+(i+1)+"</option>"

I tried entering this code before the loop, and it does not show anything. Even inside the function startup();

document.getElementById('sheetNo').innerHTML = "<option value='Sample'>Sample</option>";

I found what was the problem.
I tried changing

document.getElementById('sheetNo').innerHTML+="<option value=\""+ i +"\">"+(i+1)+"</option>"


var opt = document.createElement('option');
opt.value = i;
opt.innerHTML = parseInt(i + 1);

and it works.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.