NYCPHP Meetup

NYPHP.org

[nycphp-talk] need ajax help REVISED

Michael Southwell michael.southwell at nyphp.com
Wed May 21 21:24:38 EDT 2008


Well, one more example of "asking for help reveals the answer",
in this case partially.

This revised code shows that the blanking out upon mouseout, where
I am using a variable id, works, but I'm still not getting the color
upon mouseover, whether I use a hardcoded id or a variable
=======
....
<td style="border:thin solid"
onMouseOver="showColor( ' . $tableCounter . ' )"
onMouseOut="blankOut( ' . $tableCounter . ' )">' . $name . '</td>
....

function showColor ( i ) {
   var where = 'color' + i
   xmlHttp = getXmlHttpObject()
   var uri = 'getColor.php?where=' + where
   uri = uri + '&sid=' + Math.random()
   xmlHttp.onreadystatechange = stateChanged( where )
   xmlHttp.open( 'GET', uri, true )
   xmlHttp.send( null )
}

function blankOut ( i ) {
   var where = 'color' + i
   // this works (using a testing value instead of '' for visibility)
   document.getElementById( where ).innerHTML = 'x'
}

function stateChanged( where ) {
   if ( xmlHttp.readyState == 4 || xmlHttp.readyState == "complete" ) {
     // these both get the correct response
     // but neither loads the innerHTML
     document.getElementById( 'color1' ).innerHTML = xmlHttp.responseText
//    document.getElementById( where ).innerHTML = xmlHttp.responseText
   }
}


-- 
=================
Michael Southwell
Vice President, Education
NYPHP TRAINING:  http://nyphp.com/Training/Indepth



More information about the talk mailing list