dokeos
[ class tree: dokeos ] [ index: dokeos ] [ all elements ]

Source for file customResponseClassTest.php

Documentation is available at customResponseClassTest.php

  1. <?php
  2. require_once("../xajax.inc.php");
  3.  
  4. // Custom Response Class extends xajaxResponse
  5. {  
  6.     function addCreateOption($sSelectId$sOptionId$sOptionText$sOptionValue)  
  7.     {  
  8.         $this->addScript("addOption('".$sSelectId."','".$sOptionId."','".$sOptionText."','".$sOptionValue."');");
  9.     }
  10. }
  11.  
  12. // tests the select form
  13. function testForm($formData)
  14. {
  15.     $objResponse new customXajaxResponse();
  16.     $objResponse->addAlert("formData: " print_r($formDatatrue));
  17.     $objResponse->addAssign("submittedDiv""innerHTML"nl2br(print_r($formDatatrue)));
  18.     return $objResponse->getXML();
  19. }
  20.  
  21. // adds an option to the select 
  22. function addOption($selectId$optionData)
  23. {
  24.     $objResponse new customXajaxResponse();
  25.     $objResponse->addCreateOption($selectId$optionData['optionId']$optionData['optionText']$optionData['optionValue']);
  26.     $objResponse->addAssign("submittedDiv""innerHTML"nl2br(print_r($optionDatatrue)));
  27.     return $objResponse->getXML();
  28. }
  29.  
  30. $xajax new xajax();
  31. //$xajax->debugOn();
  32. $xajax->registerFunction("testForm");
  33. $xajax->registerFunction("addOption");
  34.  
  35.  
  36. $xajax->processRequests();
  37. ?>
  38. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  39.         "http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-transitional.dtd">
  40. <html xmlns="http://www.w3.org/1999/xhtml">
  41.     <head>
  42.         <title>Custom Response Class Test| xajax Tests</title>
  43.         <script type="text/javascript">
  44.         //javascript function to add an option to a select box
  45.         function addOption(selectId,optionId,txt,val)
  46.         {
  47.             var objOption = new Option(txt,val);
  48.             objOption.id = optionId;
  49.             document.getElementById(selectId).options.add(objOption);
  50.         }
  51.         </script>
  52.  
  53.         <?php $xajax->printJavascript("../"?>
  54.     </head>
  55.     <body>
  56.         <h2><a href="index.php">xajax Tests</a></h2>
  57.         <h1>Custom Response Class Test</h1>
  58.  
  59.         <div>
  60.             <form id="testForm1" onsubmit="return false;">
  61.                 <div>Select</div>
  62.                 <select id="selectBox" name="selectBox">
  63.                 </select>
  64.                 <div><input type="submit" value="submit" onclick="xajax_testForm(xajax.getFormValues('testForm1')); return false;" /></div>
  65.             </form>
  66.         </div>
  67.  
  68.         <div style="margin-top: 20px;">
  69.             <form id="testForm2" onsubmit="return false;">
  70.                 <fieldset style="display:inline; background-color: rgb(230,230,230);">
  71.                     <legend>New Option</legend>
  72.                     <div>Id:</div>
  73.                     <input type="text" id="optionId" name="optionId" value="option1" />
  74.                     <div>Text:</div>
  75.                     <input type="text" id="optionText" name="optionText" value="One" />
  76.                     <div>Value:</div>
  77.                     <input type="text" id="optionValue" name="optionValue" value="1" />
  78.                     <div><input type="submit" value="Add" onclick="xajax_addOption('selectBox',xajax.getFormValues('testForm2')); return false;" />                    </div>
  79.                 </fieldset>
  80.             </form>
  81.         </div>
  82.  
  83.         <div id="submittedDiv" style="margin: 3px;"></div>
  84.         
  85.     </body>
  86. </html>

Documentation generated on Thu, 12 Jun 2008 13:17:28 -0500 by phpDocumentor 1.4.1