# AJAX syntax basics

**URL:** <https://forum.kirupa.com/t/ajax-syntax-basics/245574>\
**Category:** web dev\
**Created:** [December 1, 2007, 5:00am UTC](https://forum.kirupa.com/t/ajax-syntax-basics/245574 "2007-12-01T05:00:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![NeoDreamer](https://avatars.discourse-cdn.com/v4/letter/n/ccd318/32.png) [@NeoDreamer](https://forum.kirupa.com/u/NeoDreamer)\
**Post date:** [December 1, 2007, 5:00am UTC](https://forum.kirupa.com/t/ajax-syntax-basics/245574/1 "2007-12-01T05:00:38Z")

</div>

This is my HTML

```php

<input type="text" size="30" maxlength="30" name="username" id="registerUsername" onkeyup="nameAvailable(this.value, 'availability')" />

```

This is a portion of my imported javascript file. I’ll spare you reading too much by cutting out the typical setup code in nameAvailable. This code is not working for me.

```php

function nameAvailable(username, infoBox)
{
   // ... xmlHttp creation here ...
   xmlHttp.onreadystatechange = nameAvailableReady(infoBox);
   // ... send request here ...
} 

function nameAvailableReady(infoBox) 
{	
	if ((xmlHttp.readyState == 4) || (xmlHttp.readyState == "complete"))
		document.getElementById(infoBox).innerHTML = xmlHttp.responseText;
}

```

Why does it only work if I hardcode the place the response text is supposed to be inserted? This code will work as I want it to, but it is inflexible because of the hardcoding.

```php

function nameAvailable(username, infoBox)
{
   // ... xmlHttp creation here ...
   xmlHttp.onreadystatechange = nameAvailableReady;
   // ... send request here ...
} 

function nameAvailableReady(infoBox) 
{	
	if ((xmlHttp.readyState == 4) || (xmlHttp.readyState == "complete"))
		document.getElementById("availability").innerHTML = xmlHttp.responseText;
}

```
