onclick event requires double click to load

I have an onclick event handler which runs a script to test if and element id has innerHTML == nothing.  Problem is when I click on a table row it requires a double click to load the innerHTML of the call.  Hope this makes sense as I am knew to javscript.
<script>
function loadHub(id, jid){
	var testLoad = document.getElementById('loadDiv' + id);
	if(testLoad.innerHTML == '') {
		loadJob(id, jid);
	} else {
		unloadJob(id);
	}
}
	
	
function loadJob(id, jid){
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			var ajaxDisplay = document.getElementById('loadDiv' + id);
			ajaxDisplay.innerHTML = ajaxRequest.responseText;
 
		}
	}
	var queryString = "?id=" + id + "&jid=" + jid;
	ajaxRequest.open("GET", "loadjob.php" + queryString, true);
	ajaxRequest.send(null); 
}
 
function unloadJob(id){
	var ajaxClose = document.getElementById('loadDiv' + id);
	ajaxClose.innerHTML = "";
 
}
</script>
 
<?php
while($rows=mysql_fetch_array($result)){
	$jid = $rows['JID'];
    $cid = $rows['CID'];
$total = mysql_num_rows($result);
if(is_odd($i)){
echo "<tr class = 'odd' onclick='loadHub($i, $jid)'>";
} else {
echo "<tr onclick='loadHub($i, $jid)'>";
}
echo"<td>".$rows['JID']."</td>
     <td>".$rows['CID']."</td>
     <td class = 'bunked'><ul><li>".$rows['pname']."</li>
	 						  <li class = 'bunked'>".$rows['zname']."</li></ul></td>
	 <td class = 'bunked'><ul><li>".$rows['name']."</li>
	 						  <li class = 'bunked'>".$rows['address']."</li></ul></td>
	 <td class = 'bunked'><ul><li>".formatPhone($rows['home'])."</li>
	 						  <li class = 'bunked'>".formatPhone($rows['cell'])."</li></ul></td>
     <td>".$rows['summary']."</td>
  	 </tr>";
	 if(is_odd($i)){
			echo "<tr class = 'odd' onclick='loadJob($i, $jid)'>";
		} else {
			echo "<tr onclick='loadJob($i, $jid)'>";
		}
	 if(strlen($rows['description']) < 200) {
	 echo "<td colspan = '6'>".nl2br($rows['description'])."</td>";
	 } else {
	 echo "<td colspan = '6'>See Full Description</tr>"; 
	 }
	 echo"</tr>
	 <tr class='space'><td id = 'space".$i."' colspan = '11'><div id = 'loadDiv".$i."'> </div></td></tr>";
	 
	  
$i++;
}
?>

Open in new window

cone13coneAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chad HaneyChief Technology OfficerCommented:
it is taking a double click to work because the first click it is not = '', it is null or nothing.  So your code is setting the value to '' on the first click then the second click it will respond.  try flipping the check as follows

function loadHub(id, jid){
        var testLoad = document.getElementById('loadDiv' + id);
        if(testLoad.innerHTML != '') {
               unloadJob(id);
        } else {
               loadJob(id, jid);
        }
}

Open in new window

0
cone13coneAuthor Commented:
Dachusa the above did not work, its still require a dbl click the first time to load. =\
0
cone13coneAuthor Commented:
This fixed it, thanks.
function loadHub(id, jid, cid){
        var testLoad = document.getElementById('loadDiv' + id);
        if(!testLoad.innerHTML) {
               unloadJob(id);
        } else {
               loadJob(id, jid, cid);
        }
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
AJAX

From novice to tech pro — start learning today.