Change Style with Xajax and PHP

Change Style with Xajax and PHP

Here we see a simple xajax and php example of how to change the style of a div. This also shows how the text in the div may be changed. It works by having xajax call the changeStyle function which, as the name suggests, changes the style of the div. Comments through-out the code will show the way.

/*** include the xajax libs ***/
include 'xajax/xajax_core/';
/*** a new xajax object ***/
$xajax=new xajax();
/*** register a new xajax funtion ***/

 * @function changeStyle
 * @change the style of a div
 * @return obj
function changeStyle()
/*** a new response object ***/
$objResponse=new xajaxResponse();
/*** ass the new text to the my_div div ***/
$objResponse->assign("my_div""innerHTML""New content here!");
/*** assign a new style to the my_div div ***/
/*** return the object Response ***/
return $objResponse;
/*** process the request ***/ 
/*** stuff the xajax javascript into a variable ***/
$xajax_js $xajax->getJavascript('/xajax');



 <title>XAJAX and PHP</title>
 <?php echo $xajax_js?>

 <style type="text/css">
    color: #993366;
    font-size: 24px;
    font-family: "Times New Roman", Times, serif;
    color: #336699;
    font-size: 16px;
    font-family:Helvetica, Arial, sans-serif

 <h2>Change style with xajax</h2>
 <div id="my_div" class="old_css">Change this line</div>
 <form action="post" method="post" name="my_form" id="my_form">
 <input type="button" value="Change!" onClick="xajax_changeStyle();" />